首页 > 代码库 > 修改距离当天日期7天以上的AD用户密码,并生成日志
修改距离当天日期7天以上的AD用户密码,并生成日志
Import-Module ActiveDirectory $outputlogt = @() $outputlogf = @() $users = @() #$path1 = "ou=测试,dc=bjgas,dc=com" Write-Host "请输入第1个遍历路径" $user1 = Read-Host $User1 = Get-ADUser -Filter * -SearchBase "$path1" Write-Host "请输入第2个遍历路径" $path2 = Read-Host $user2 = Get-ADUser -Filter * -SearchBase "$path2" $users = $user1 #+ $user2 $nowdate = (get-date -Format "yyyy/mm/dd hh:mm").ToString() #Write-Host "Please Enter a NewPassword" #$newpass = "Read-Host" write-host "Please Enter a NewPssword!" Write-Warning "The Password will be applied to all Users in the $path1 and $path2 container" $newpass = Read-Host set-location c:$WorkingPath = ‘.\log\‘ foreach ($user in $users) { $userlogondate = Get-ADUser -Identity $user.Name -Properties LastLogondate | Select-Object -Property LastLogondate $days = (New-TimeSpan $userlogondate.lastlogondate).Days if ($days -gt 7) { #write-host "Please Enter a NewPssword!" #Write-Warning "The Password will be applied to all Users in the $path1 and $path2 container" #$newpass = Read-Host $user | Set-ADAccountPassword -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$newpass" -Force) $Log = New-Object PSObject $Log | Add-Member NoteProperty "UserName" $user.name $Log | Add-Member NoteProperty "LastLogonDate" $userlogondate $Log | Add-Member NoteProperty "ModifyPassWord" "True" $OutPutLogT += $Log $OutPutLogT | Export-Csv -Encoding UTF8 -NoTypeInformation -Path "$workingpath‘true‘.csv" } else { $Logf = New-Object PSObject $Logf | Add-Member NoteProperty "UserName" $user.name $Logf | Add-Member NoteProperty "LastLogonDate" $userlogondate $Logf | Add-Member NoteProperty "ModifyPassWord" "false" $OutPutLogF += $Logf $OutPutLogF | Export-Csv -Encoding UTF8 -NoTypeInformation -Path "$workingpath‘False‘.csv" } }
本文出自 “百草素心” 博客,请务必保留此出处http://suxin.blog.51cto.com/535505/1587515
修改距离当天日期7天以上的AD用户密码,并生成日志
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。