-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-AzWorkspaceManagerAssignment.ps1
More file actions
108 lines (96 loc) · 4.91 KB
/
Get-AzWorkspaceManagerAssignment.ps1
File metadata and controls
108 lines (96 loc) · 4.91 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function Get-AzWorkspaceManagerAssignment {
[cmdletbinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[ValidatePattern('^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$', ErrorMessage="It does not match expected pattern '{1}'")]
[Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceNameCompleterAttribute(
"Microsoft.OperationalInsights/workspaces",
"ResourceGroupName"
)][string]$WorkspaceName,
[Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)]
[Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters.ResourceGroupCompleterAttribute()]
[string]$ResourceGroupName,
[Parameter(Mandatory = $false, ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[ValidatePattern('^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$', ErrorMessage="It does not match expected pattern '{1}'")]
[string]$Name
)
begin {
Invoke-AzWorkspaceManager -FunctionName $MyInvocation.MyCommand.Name
}
process {
if ($ResourceGroupName) {
$null = Get-AzWorkspaceManager -Name $WorkspaceName -ResourceGroupName $ResourceGroupName
}
else {
$null = Get-AzWorkspaceManager -Name $WorkspaceName
}
if ($null -ne $Name) {
$uri = "$($SessionVariables.workspace)/providers/Microsoft.SecurityInsights/workspaceManagerAssignments/$($Name)?api-version=$($SessionVariables.apiVersion)"
}
else {
$uri = "$($SessionVariables.workspace)/providers/Microsoft.SecurityInsights/workspaceManagerAssignments?api-version=$($SessionVariables.apiVersion)"
}
if ($SessionVariables.workspaceManagerConfiguration -eq 'Enabled') {
try {
Write-Verbose "List Microsoft Sentinel Workspace Manager Assignments for workspace '$WorkspaceName'"
$requestParam = @{
Headers = $authHeader
Uri = $uri
Method = 'GET'
ErrorVariable = 'ErrVar'
}
if ($Name) {
$apiResponse = (Invoke-RestMethod @requestParam)
}
else {
$apiResponse = (Invoke-RestMethod @requestParam).value
}
if ($apiResponse -ne '') {
foreach ($object in $apiResponse) {
$result = Format-Result -Message $apiResponse
}
return $result
}
else {
Write-Message -FunctionName $($MyInvocation.MyCommand.Name) -Message "No Workspace Manager Assignments found for workspace '$WorkspaceName'" -Severity 'Information'
}
}
catch {
if ($ErrVar.Message -like '*ResourceNotFound*') {
Write-Message -FunctionName $($MyInvocation.MyCommand.Name) -Message "No Workspace Manager Assignments with name '$($Name)' found under workspace '$WorkspaceName'" -Severity 'Error'
}
else {
Write-Message -FunctionName $($MyInvocation.MyCommand.Name) -Message (($ErrVar.ErrorRecord) | ConvertFrom-Json).error.message -Severity 'Error'
}
}
}
else {
Write-Message -FunctionName $($MyInvocation.MyCommand.Name) -Message "The Workspace Manager configuration is not 'Enabled' for workspace '$WorkspaceName'" -Severity 'Information'
}
}
<#
.SYNOPSIS
Get the Microsoft Sentinel Workspace Manager Groups
.DESCRIPTION
The Get-AzWorkspaceManagerAssignment cmdlet gets the Microsoft Sentinel Workspace Manager Assignments by just specifying the workspace name
When the workspace manager configuration is not 'Enabled' for the workspace, the cmdlet will return an information message
If a Name is specified, the cmdlet will return the details of the workspace manager assignment
.PARAMETER WorkspaceName
The Name of the log analytics workspace
.PARAMETER ResourceGroupName
The name of the ResouceGroup where the log analytics workspace is located
.PARAMETER Name
The name of the workspace manager assignment
.EXAMPLE
Get-AzWorkspaceManagerAssignment -WorkspaceName 'MyWorkspace'
This example gets all the Microsoft Sentinel Workspace Manager Assignments for the workspace 'MyWorkspace'
.EXAMPLE
Get-AzWorkspaceManagerAssignment -WorkspaceName 'MyWorkspace' -Name 'MyWorkspaceManagerAssignment'
This example gets the details of the Microsoft Sentinel Workspace Manager Assignment 'MyWorkspaceManagerAssignment' for the workspace 'MyWorkspace'
.LINK
Add-AzWorkspaceManagerAssignment
Remove-AzWorkspaceManagerAssignment
#>
}