-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathGet-EntraBetaUserManager.ps1
More file actions
91 lines (86 loc) · 4.44 KB
/
Get-EntraBetaUserManager.ps1
File metadata and controls
91 lines (86 loc) · 4.44 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
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------
function Get-EntraBetaUserManager {
[CmdletBinding(DefaultParameterSetName = 'GetQuery')]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Specifies the ID of a user (as a UserPrincipalName or ObjectId) in Microsoft Entra ID.")]
[Alias('ObjectId', 'UPN', 'Identity', 'UserPrincipalName')]
[ValidateNotNullOrEmpty()]
[ValidateScript({
if ($_ -match '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or
$_ -match '^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') {
return $true
}
throw "UserId must be a valid email address or GUID."
})]
[System.String] $UserId,
[Parameter(Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, HelpMessage = "Properties to include in the results.")]
[Alias("Select")]
[System.String[]] $Property
)
PROCESS {
$params = @{}
$customHeaders = New-EntraBetaCustomHeaders -Command $MyInvocation.MyCommand
if ($PSBoundParameters.ContainsKey("Verbose")) {
$params["Verbose"] = $PSBoundParameters["Verbose"]
}
if ($null -ne $PSBoundParameters["UserId"]) {
$params["UserId"] = $PSBoundParameters["UserId"]
}
if ($PSBoundParameters.ContainsKey("Debug")) {
$params["Debug"] = $PSBoundParameters["Debug"]
}
if ($null -ne $PSBoundParameters["WarningVariable"]) {
$params["WarningVariable"] = $PSBoundParameters["WarningVariable"]
}
if ($null -ne $PSBoundParameters["InformationVariable"]) {
$params["InformationVariable"] = $PSBoundParameters["InformationVariable"]
}
if ($null -ne $PSBoundParameters["InformationAction"]) {
$params["InformationAction"] = $PSBoundParameters["InformationAction"]
}
if ($null -ne $PSBoundParameters["OutVariable"]) {
$params["OutVariable"] = $PSBoundParameters["OutVariable"]
}
if ($null -ne $PSBoundParameters["OutBuffer"]) {
$params["OutBuffer"] = $PSBoundParameters["OutBuffer"]
}
if ($null -ne $PSBoundParameters["ErrorVariable"]) {
$params["ErrorVariable"] = $PSBoundParameters["ErrorVariable"]
}
if ($null -ne $PSBoundParameters["PipelineVariable"]) {
$params["PipelineVariable"] = $PSBoundParameters["PipelineVariable"]
}
if ($null -ne $PSBoundParameters["ErrorAction"]) {
$params["ErrorAction"] = $PSBoundParameters["ErrorAction"]
}
if ($null -ne $PSBoundParameters["WarningAction"]) {
$params["WarningAction"] = $PSBoundParameters["WarningAction"]
}
if ($null -ne $PSBoundParameters["Property"]) {
$params["Property"] = $PSBoundParameters["Property"]
}
Write-Debug("============================ TRANSFORMATIONS ============================")
$params.Keys | ForEach-Object { "$_ : $($params[$_])" } | Write-Debug
Write-Debug("=========================================================================`n")
$response = Get-MgBetaUserManager @params -Headers $customHeaders -ErrorAction Stop
try {
$data = $response | ConvertTo-Json -Depth 10 | ConvertFrom-Json
$targetList = @()
foreach ($res in $data) {
$targetType = New-Object Microsoft.Graph.Beta.PowerShell.Models.MicrosoftGraphDirectoryObject
$res.PSObject.Properties | ForEach-Object {
$propertyName = $_.Name.Substring(0, 1).ToUpper() + $_.Name.Substring(1)
$propertyValue = $_.Value
$targetType | Add-Member -MemberType NoteProperty -Name $propertyName -Value $propertyValue -Force
}
$targetType.PSTypeNames.Insert(0, "Microsoft.Entra.Beta.User.Manager")
$targetList += $targetType
}
$targetList
}
catch {}
}
}