-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostMessage-MigrationBatch.ps1
More file actions
44 lines (33 loc) · 1.18 KB
/
Copy pathPostMessage-MigrationBatch.ps1
File metadata and controls
44 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Clear-Host
Set-Location -Path $PSScriptRoot
# Input Parameters
$developerToken = Read-Host 'Enter Your Yammer Developer Token' -MaskInput
$groupId= Read-Host 'Input the Encoded Yammer Group'
$BatchFileName= Read-Host 'Input the Name of XLS Batch file'
if (Get-Module -ListAvailable -Name 'ImportExcel')
{
Write-Host "Module exists. Nothing to do!" -ForegroundColor Magenta
}
else
{
Write-Warning "ImportExcel module not present. Installation in progress"
Install-Module -Name ImportExcel -Force
}
$uri="https://www.yammer.com/api/v1/messages.json"
$headers = @{ Authorization=("Bearer " + $developerToken) }
$file = Import-Excel ($BatchFileName + '.xlsx') -HeaderName 'Subject', 'Created By', 'Replies', 'Created', 'Body'
$skipFirst = $true
foreach ($currBody in $file.Body)
{
if ($skipFirst -eq $true)
{
$skipFirst = $false
continue
}
#Debug Message
#Write-Host "----- $currBody"
#break
$body=@{group_id=$groupId;body=$currBody}
Invoke-WebRequest -Uri $uri -Method POST -Headers $headers -Body $body | Out-Null
Write-Host 'Message Posted on Yammer' -ForegroundColor Green
}