Powershell - 选择并“动态”更新属性


0

我正在尝试查找具有null属性(“terminalservicesprofilepath”)的AD用户,并在同一命令中更新此属性。

我可以选择用户,但如何“动态”更新属性?

Get-ADUser -Filter {(ObjectClass -eq "user") -and (Enabled -eq $true)} -server $DC[1] -Properties * | select SAMAccountName,displayName,DistinguishedName,Mail,Homemdb,@{Name="TSP";Expression={([adsi]("LDAP://$($_.distinguishedName)")).psbase.InvokeGet("terminalservicesprofilepath")}} | where {($_.DistinguishedName -match ".OU=USERS.") -and ($_.TSP -eq $null)} 

Answers:


1

不幸的是,这并不像Set-ADUser那样简单。试试这个脚本:

$users = Get-ADUser -Filter {(Enabled -eq $true)} -server $DC[1] -Properties * -SearchBase "OU=Users,DC=<Domain>,DC=<TLD>" | Select-Object SAMAccountName,DisplayName,DistinguishedName,Mail,Homemdb,@{Name="TSP";Expression={([adsi]("LDAP://$($users.distinguishedName)")).psbase.InvokeGet("terminalservicesprofilepath")}
$nullTSP = Where-Object {$_.TSP -eq $null} 

foreach ($TSP in $nullTSP) {
    $TSP.DistinguisedName.psbase.Invokeset("terminalservicesprofilepath","\\<server>\<share>\")
    $TSP.DistinguishedName.setinfo()
}

如果这对您有用,请告诉我!

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.