Tuesday, 15 May 2012

powershell - Where object based on a variable content -



powershell - Where object based on a variable content -

i have problem office365 powershell script

$expireuser = get-msoluser | where-object {$_.passwordneverexpires -eq $false} $expireuser | ft displayname, userprincipalname, passwordneverexpires $userinput = read-host 'users in table have parameter passwordneverexpires set on $false. set $true? (y/n)' if ($userinput -eq "y"){ get-msoluser | where-object {$_.passwordneverexpires -eq $false} | set-msoluser -passwordneverexpires $true write-host "down visible parameters of users modified." $expireusercheck = get-msoluser | where-object {$_.userprincipalname -eq $expireuser.userprincipalname} $expireusercheck | ft displayname, userprincipalname, passwordneverexpires } elseif ($userinput -eq "n") {write-host "no alter made"} else {write-host "input not managed"}

the process of alter parameters works everytime right basic function of script ok problem if 1 user have parameter set check works showing me table displayname, userprincipalname , $true under passwordneverexpire. if 2 or more user in $expireuser variable nil appears when sec table must show.

any idea?

many thanks, marco

create array of userprincipalnames using following:

$arrayofuserprincipalnames = $expireuser | select -expandproperty userprincipalname

then alter line:

$expireusercheck = get-msoluser | where-object {$_.userprincipalname -eq $expireuser.userprincipalname}

to:

$expireusercheck = get-msoluser | where-object {$_.userprincipalname -in $arrayofuserprincipalnames}

powershell

No comments:

Post a Comment