使用功能时无法查看新的AD属性

时间:2019-06-10 17:47:32

标签: powershell active-directory

我们在AD中创建了两个新属性(UguestRole,UguestRoleDtl)。尝试以下PowerShell功能将不会显示新属性。

我可以手动运行脚本的get部分,并且属性将显示。

Function Admin-CheckAD {

$UserID = $IsUser = ""

Clear-Host
Write-Host "Get Active Directory Data"
$UserID = ""
$UserID = Read-Host "Enter User ID"

If ($UserID) {
    $IsUser = Get-AdUser -LDAPFilter "(sAMAccountName=$UserID)"
    If ($IsUser -eq $Null){
        Write-Warning "User does not exist in AD";Return
    } Else {
        Get-Aduser $UserID -Properties samaccountname, DisplayName, LastLogonDate, PasswordLastSet, PasswordExpired, Mail, Enabled, UguestRole, UguestRoleDtl, AccountExpirationDate, Description |
        Select-Object @{N='User ID';E={($_.samaccountname).ToUpper()}}, DisplayName, LastLogonDate, PasswordLastSet, PasswordExpired, Mail, Enabled, UguestRole, UguestRoleDtl, @{N='Expire Date';E={([DateTime]$psitem.AccountExpirationDate).AddDays(-1).ToShortDateString()}}, Description |
        Format-List
      }
    }
}

我希望看到...

User ID         : JOEUSER
DisplayName     : User, Joe
LastLogonDate   : 6/10/2019 6:29:21 AM
PasswordLastSet : 5/22/2019 10:05:43 AM
PasswordExpired : False
Mail            : joe.user@email.com
Enabled         : True
UguestRole      : CC
UguestRoleDtl   : Builder
Expire Date     :
Description     : CC User

但是我得到的只是...

User ID         : JOEUSER
Name            : User, Joe
LastLogonDate   : 6/10/2019 6:29:21 AM
PasswordLastSet : 5/22/2019 10:05:43 AM
PasswordExpired : False
Mail            : joe.user@email.com
Enabled         : True
Expire Date     :
Description     : CC User

0 个答案:

没有答案