任何人都可以告诉我如何使用powershell来检索有关帐户过期的用户的AD信息,并使用Office字段中的信息。
喜欢此名称,Office,Expiredate
以及如何从登录在服务器上的useraccount发送它。
BTW:QADuser不是一个选项。
答案 0 :(得分:2)
试试这个:
foreach ($user in (gwmi -namespace "root/directory/ldap" -class "ds_user"))
{
write " `
$user.DS_name, `
$user.DS_physicalDeliveryOfficeName,
(w32tm /ntte $user.DS_accountExpires) `
" `
| Out-File ".\userlist.txt" -Append -Encoding ASCII;
}
答案 1 :(得分:0)
你可以这样做,只使用ADSI(在没有任何管理单元的PowerShell 1中工作)
Clear-Host
$dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://WM2008R2ENT:389/dc=dom,dc=fr","jpb@dom.fr","PWD")
$dsLookFor = new-object System.DirectoryServices.DirectorySearcher($dn)
$dsLookFor.Filter = "(sAMAccountName=jblanc)";
$dsLookFor.SearchScope = "subtree";
$n = $dsLookFor.PropertiesToLoad.Add("cn");
$n = $dsLookFor.PropertiesToLoad.Add("distinguishedame");
$n = $dsLookFor.PropertiesToLoad.Add("samaccountname");
$n = $dsLookFor.PropertiesToLoad.Add("name");
$n = $dsLookFor.PropertiesToLoad.Add("accountexpires");
$n = $dsLookFor.PropertiesToLoad.Add("department");
$lstUsr = $dsLookFor.findall()
foreach ($usrTmp in $lstUsr)
{
Write-Host $usrTmp.Properties["samaccountname"]
Write-Host $usrTmp.Properties["name"]
#Write-Host $usrTmp.Properties["accountexpires"].value
Write-Host $([datetime]::FromFileTime($($usrTmp.Properties["accountexpires"])))
Write-Host $usrTmp.Properties["department"]
}
答案 2 :(得分:0)
Import-Module ActiveDirectory
Search-ADAccount -AccountExpiring -TimeSpan "365" -UsersOnly | Get-ADUser -Prop
Description,samAccountName,AccountExpirationDate | Select-Object
Name,samAccountName,Description,AccountExpirationDate | Sort-Object AccountExpirationDate |
Format-Table -property * -AutoSize | Out-file "FilePath\name.txt" -Width 500