-
Notifications
You must be signed in to change notification settings - Fork 6
/
Update-AzureOMSWorkSpaceKey.ps1
70 lines (64 loc) · 1.84 KB
/
Update-AzureOMSWorkSpaceKey.ps1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<#
.DESCRIPTION
Long description
.PARAMETER Servers
Script expect server names it can connect to over the network (Servername.Domain.local)
Invoke-command uses the WinRM ports.
TCP/5985 = HTTP
TCP/5986 = HTTPS
Parameter accepts an array.
.PARAMETER WorkSpaceID
This is the workspaceDI
.PARAMETER WorkSpaceKey
This is the WorkSpaceKey.
.EXAMPLE
$servers = Get-ADComputer -Filter {operatingsystem -like "*server*"}
Update-OMSWorkSpaceKey -Servers $Servers -WorkSpaceID 'XXXXXXXXXXXXXXXXXX' -WorkSpaceKey 'XXXXXXXXXXXXXXXXXX'
.LINK
https://bwit.blog/bulk-update-oms-workspace-key-powershell/
#>
function Update-OMSWorkSpaceKey
{
[CmdletBinding()]
param (
[Parameter (Mandatory = $true)]
[string[]]
$Server,
[Parameter (Mandatory = $true)]
$WorkSpaceID,
[Parameter (Mandatory = $true)]
$WorkSpaceKey
)
begin
{
Write-Verbose 'Update-OMSWorkSpaceKey: begin: Creating Scriptblock for remote servers.'
$Scriptblock = {
$WorkspaceID = $WorkSpaceID
$WorkspaceKey = $WorkSpaceKey
$AgentCfg = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
$AgentCfg.GetCloudWorkspaces()
$AgentCfg.AddCloudWorkspace($WorkspaceID, $WorkspaceKey)
Restart-Service HealthService
}
}
process
{
Write-Verbose 'Update-OMSWorkSpaceKey: process: Starting script to invoke scriptblock to serverlist.'
#foreach ($Srv in $Server)
#{
Write-Verbose "Update-OMSWorkSpaceKey: process: Invoke-Command on srv: $Server"
try
{
Invoke-Command -ComputerName $Server -ScriptBlock $scriptblock
}
catch
{
continue
}
#}
}
end
{
return "Script finished updating keys."
}
}