PowerShell foreach过滤器

PowerShell 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

我尝试开发这样的增量密码更改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@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行:

  • 用户ID大于当前日期时间减去2小时(四舍五入到较低的小时数)加上以下格式的“00000”:YYYYMMDDH00000-例如,如果当前时间为2012年6月15日下午3:35,则过滤器应包括:201206151300000,以及
  • 在lastprocessedd.csv中存储的userID高于lastID

  • 脚本执行完成后,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
    }