Update to Set-HVMachine to ease the assignment to users machines
This commit is contained in:
@@ -8454,6 +8454,11 @@ PARAMETER Key
|
|||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
$Value,
|
$Value,
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[ValidatePattern("^.+?[@\\].+?$")]
|
||||||
|
[string]
|
||||||
|
$User,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
$HvServer = $null
|
$HvServer = $null
|
||||||
)
|
)
|
||||||
@@ -8481,6 +8486,11 @@ PARAMETER Key
|
|||||||
$machineList.add($macineObj.id, $macineObj.base.Name)
|
$machineList.add($macineObj.id, $macineObj.base.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($machineList.count -eq 0) {
|
||||||
|
Write-Error "Machine $machineName not found - try fqdn"
|
||||||
|
[System.gc]::collect()
|
||||||
|
return
|
||||||
|
}
|
||||||
} elseif ($PSCmdlet.MyInvocation.ExpectingInput -or $Machine) {
|
} elseif ($PSCmdlet.MyInvocation.ExpectingInput -or $Machine) {
|
||||||
foreach ($item in $machine) {
|
foreach ($item in $machine) {
|
||||||
if (($item.GetType().name -eq 'MachineNamesView') -or ($item.GetType().name -eq 'MachineInfo')) {
|
if (($item.GetType().name -eq 'MachineNamesView') -or ($item.GetType().name -eq 'MachineInfo')) {
|
||||||
@@ -8498,6 +8508,22 @@ PARAMETER Key
|
|||||||
} elseif ($key -or $value) {
|
} elseif ($key -or $value) {
|
||||||
Write-Error "Both key:[$key] and value:[$value] needs to be specified"
|
Write-Error "Both key:[$key] and value:[$value] needs to be specified"
|
||||||
}
|
}
|
||||||
|
if ($User) {
|
||||||
|
$userInfo = Get-UserInfo -UserName $User
|
||||||
|
$UserOrGroupName = $userInfo.Name
|
||||||
|
$Domain = $userInfo.Domain
|
||||||
|
$filter1 = Get-HVQueryFilter 'base.name' -Eq $UserOrGroupName
|
||||||
|
$filter2 = Get-HVQueryFilter 'base.domain' -Eq $Domain
|
||||||
|
$filter3 = Get-HVQueryFilter 'base.group' -Eq $false
|
||||||
|
$andFilter = Get-HVQueryFilter -And -Filters @($filter1, $filter2, $filter3)
|
||||||
|
$results = Get-HVQueryResult -EntityType ADUserOrGroupSummaryView -Filter $andFilter -HvServer $HvServer
|
||||||
|
if ($results.length -ne 1) {
|
||||||
|
Write-Host "Unable to find specific user with given search parameters"
|
||||||
|
[System.gc]::collect()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$updates += Get-MapEntry -key 'base.user' -value $results[0].id
|
||||||
|
}
|
||||||
|
|
||||||
if ($Maintenance) {
|
if ($Maintenance) {
|
||||||
if ($Maintenance -eq 'ENTER_MAINTENANCE_MODE') {
|
if ($Maintenance -eq 'ENTER_MAINTENANCE_MODE') {
|
||||||
|
|||||||
Reference in New Issue
Block a user