Powershell獲取1年內未改密碼的用戶

2023-01-16 15:17:13 來源:51CTO博客


(資料圖片僅供參考)

Powershell獲取1年內未改密碼的用戶

1、定義OU搜索范圍:OU=BYSSOFT_OBJECT,DC=byssoft,DC=com

2、定義輸出結果文件

#建議保存編碼為:bom頭 + utf8$輸入ou = "OU=BYS_Users,OU=BYS_Object,DC=byssoft,DC=com"$輸出文件 = "d:\expireduser.txt"$1年前 = (Get-Date).addyears(0)$users = Get-ADUser -SearchBase $輸入ou -filter { PasswordLastSet -lt $1年前 } -Properties samaccountname,msDS-UserPasswordExpiryTimeComputed,PasswordNeverExpires,PasswordLastSet$結果 = @()foreach ($user in $users){  $a = [PSCustomObject]@{  samaccountname = $user.samaccountname  ou             = $user.DistinguishedName  密碼更改日期         = $user.PasswordLastSet  密碼過期日期         = [datetime]::FromFileTime($user."msDS-UserPasswordExpiryTimeComputed")  #密碼永不過期         = $user.PasswordNeverExpires  }  $結果 += $a}#$結果 | Sort-Object -Unique | Export-Csv -LiteralPath $輸出文件 -Encoding unicode -NoTypeInformation$結果 |  Export-Csv -LiteralPath $輸出文件 -Encoding unicode -NoTypeInformation

3、執行成功

4、輸出結果

標簽: 輸出文件 結果文件 搜索范圍

上一篇:從 Kubectl Top 說起, 談談 Kubernetes 是如何進行資源監控的?
下一篇:天天速讀:如何實現大地圖漫游功能