PowerShell foreach过滤器
我尝试开发这样的增量密码更改PowerShell脚本 输入csv文件:D:\pws\newpws.csvPowerShell foreach过滤器,powershell,passwords,office365,Powershell,Passwords,Office365,我尝试开发这样的增量密码更改PowerShell脚本 输入csv文件:D:\pws\newpws.csv userID,userIdentity,passwd 201206151300057,John.Doe@contoso.com,pa$$worD1 201206151301452,Tommy.Toe@contoso.com,pa$$worD2 201206151302871,Vince.Voe@contoso.com,pa$$worD3 201206151305021,William.Woe
userID,userIdentity,passwd
201206151300057,John.Doe@contoso.com,pa$$worD1
201206151301452,Tommy.Toe@contoso.com,pa$$worD2
201206151302871,Vince.Voe@contoso.com,pa$$worD3
201206151305021,William.Woe@contoso.com,pa$$worD4
201206151306433,Xerxes.Xoe@contoso.com,pa$$worD5
201206151346790,Yvonne.Yoe@contoso.com,pa$$worD6
输出csv文件:D:\pws\lastprocessedd.csv
lastID
201206141186509
到目前为止,我只有这个:
import-csv D:\pws\newpws.csv | foreach {
Set-MSOnlineUserPassword -Identity $_.userIdentity -Password $_.passwd -ChangePasswordOnNextLogon:$true -Credential $cred
}
我想修改此脚本,使其仅处理以下csv行:
脚本执行完成后,lastprocessedd.csv中的lastID应使用newpws.csv中最后一行的userID更新。您需要在管道的
Foreach
阶段之前插入,其中过滤器,例如:
userID,userIdentity,passwd
201206151300057,John.Doe@contoso.com,pa$$worD1
201206151301452,Tommy.Toe@contoso.com,pa$$worD2
201206151302871,Vince.Voe@contoso.com,pa$$worD3
201206151305021,William.Woe@contoso.com,pa$$worD4
201206151306433,Xerxes.Xoe@contoso.com,pa$$worD5
201206151346790,Yvonne.Yoe@contoso.com,pa$$worD6
import-csv D:\pws\newpws.csv |
where {$_.userID -gt $lastID -and ...} |
foreach { Set-MSOnlineUserPassword -Identity $_.userIdentity `
-Password $_.passwd -ChangePasswordOnNextLogon:$true -Credential $cred
}