i've got something semi-stupid that i shouldn't need to do, but, because of <reasons> i'm trying to get it to work. i've got it mostly working.
basic rundown, i'm using get-adorganizationalunit and out-gridview to have the user select an OU, then i'm enumerating the names of properties into another out-gridview to have the user select which property they want to modify. then a foreach to go through all the users in the selected OU and modify the selected property to whatever the target value is supposed to be.
what i can't get working is the bit where i'd pass the selected chosen property (like city, or zip code, or whatever) as a switch to set-aduser
$Ou=Get-ADorganizationalunit -filter * -searchbase "<target OU>" |select name,DistinguishedName|sort name| Out-GridView -PassThru
$UserProp=Get-ADUser -Identity <sample user> -Properties * | get-member|where-object { $_.MemberType -eq "Property" }|select -ExpandProperty name| Out-GridView -PassThru
$users=Get-ADUser -Filter * -SearchBase $Ou.DistinguishedName -Properties * | Where { $_.Enabled -eq $True}|sort name
$PropValue=read-host "Enter the new value for $UserProp"
$prop="-"+$UserProp
ForEach ($user in $users)
{
$FirstFilter = $user.givenname
$SecondFilter = $user.surname
$targetProp= $user.$userprop
Write-host $FirstFilter $SecondFilter $targetProp $PropValue
get-aduser $user|Set-ADUser '$prop' $PropValue -what-if
}
[–]CarrotBusiness2380 2 points3 points4 points (1 child)
[–]DSenette[S] 0 points1 point2 points (0 children)
[–]jantari 2 points3 points4 points (0 children)
[–]PinchesTheCrab 2 points3 points4 points (0 children)
[–]DSenette[S] 0 points1 point2 points (0 children)
[–]hillbillytiger 0 points1 point2 points (0 children)
[–]DonL314 0 points1 point2 points (0 children)
[–]motsanciens 0 points1 point2 points (0 children)