Implement Get-SsoPersonUser by Group
This commit is contained in:
@@ -394,6 +394,11 @@ function Get-SsoPersonUser {
|
|||||||
Get-SsoPersonUser -Name admin -Domain vsphere.local
|
Get-SsoPersonUser -Name admin -Domain vsphere.local
|
||||||
|
|
||||||
Gets person user accounts which contain name 'admin' in 'vsphere.local' domain
|
Gets person user accounts which contain name 'admin' in 'vsphere.local' domain
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-SsoGroup -Name 'Administrators' -Domain 'vsphere.local' | Get-SsoPersonUser
|
||||||
|
|
||||||
|
Gets person user accounts members of 'Administrators' group
|
||||||
#>
|
#>
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
@@ -406,6 +411,7 @@ function Get-SsoPersonUser {
|
|||||||
$Name,
|
$Name,
|
||||||
|
|
||||||
[Parameter(
|
[Parameter(
|
||||||
|
ParameterSetName = 'ByNameAndDomain',
|
||||||
Mandatory=$false,
|
Mandatory=$false,
|
||||||
ValueFromPipeline=$false,
|
ValueFromPipeline=$false,
|
||||||
ValueFromPipelineByPropertyName=$false,
|
ValueFromPipelineByPropertyName=$false,
|
||||||
@@ -413,6 +419,15 @@ function Get-SsoPersonUser {
|
|||||||
[string]
|
[string]
|
||||||
$Domain = 'localos',
|
$Domain = 'localos',
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
ParameterSetName = 'ByGroup',
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$false,
|
||||||
|
HelpMessage='Searches members of the specified group')]
|
||||||
|
[VMware.vSphere.SsoAdminClient.DataTypes.Group]
|
||||||
|
$Group,
|
||||||
|
|
||||||
[Parameter(
|
[Parameter(
|
||||||
Mandatory=$false,
|
Mandatory=$false,
|
||||||
ValueFromPipeline=$false,
|
ValueFromPipeline=$false,
|
||||||
@@ -439,21 +454,31 @@ function Get-SsoPersonUser {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($personUser in $connection.Client.GetLocalUsers(
|
$personUsers = $null
|
||||||
(RemoveWildcardSymbols $Name),
|
|
||||||
$Domain)) {
|
|
||||||
|
|
||||||
|
if ($Group -ne $null) {
|
||||||
|
$personUsers = $connection.Client.GetPersonUsersInGroup(
|
||||||
|
(RemoveWildcardSymbols $Name),
|
||||||
|
$Group)
|
||||||
|
} else {
|
||||||
|
$personUsers = $connection.Client.GetLocalUsers(
|
||||||
|
(RemoveWildcardSymbols $Name),
|
||||||
|
$Domain)
|
||||||
|
}
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($Name) ) {
|
if ($personUsers -ne $null) {
|
||||||
Write-Output $personUser
|
foreach ($personUser in $personUsers) {
|
||||||
} else {
|
if ([string]::IsNullOrEmpty($Name) ) {
|
||||||
# Apply Name filtering
|
|
||||||
if ((HasWildcardSymbols $Name) -and `
|
|
||||||
$personUser.Name -like $Name) {
|
|
||||||
Write-Output $personUser
|
|
||||||
} elseif ($personUser.Name -eq $Name) {
|
|
||||||
# Exactly equal
|
|
||||||
Write-Output $personUser
|
Write-Output $personUser
|
||||||
|
} else {
|
||||||
|
# Apply Name filtering
|
||||||
|
if ((HasWildcardSymbols $Name) -and `
|
||||||
|
$personUser.Name -like $Name) {
|
||||||
|
Write-Output $personUser
|
||||||
|
} elseif ($personUser.Name -eq $Name) {
|
||||||
|
# Exactly equal
|
||||||
|
Write-Output $personUser
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -260,6 +260,24 @@ Describe "PersonUser Tests" {
|
|||||||
# Assert
|
# Assert
|
||||||
$actual | Should -Be $null
|
$actual | Should -Be $null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It 'Gets person users members of Administrators group' {
|
||||||
|
# Arrange
|
||||||
|
$connection = Connect-SsoAdminServer `
|
||||||
|
-Server $VcAddress `
|
||||||
|
-User $User `
|
||||||
|
-Password $Password `
|
||||||
|
-SkipCertificateCheck
|
||||||
|
|
||||||
|
# Act
|
||||||
|
$actual = Get-SsoGroup -Name 'Administrators' -Domain 'vsphere.local' | Get-SsoPersonUser
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
$actual | Should -Not -Be $null
|
||||||
|
$actual.Count | Should -BeGreaterThan 0
|
||||||
|
$actual[0].Name | Should -Not -Be $null
|
||||||
|
$actual[0].Domain | Should -Be 'vsphere.local'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "Set-SsoPersonUser" {
|
Context "Set-SsoPersonUser" {
|
||||||
|
|||||||
Reference in New Issue
Block a user