0

谁能告诉我如何使用 powershell 检索有关帐户过期的用户的 AD 信息,这些信息来自 Office 字段。

喜欢这个名字,办公室,过期

以及如何从登录服务器的用户帐户发送它。

顺便说一句:QADuser 不是一个选项。

4

3 回答 3

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;
}
于 2012-11-25T23:24:25.503 回答
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  
于 2013-01-22T13:58:51.610 回答
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"]
}
于 2012-11-23T13:34:37.123 回答