我让这个脚本工作正常,直到最终用户想要不同格式的标题。这是使用 ActiveDirectory 模块从 AD 进行的简单转储,但是现在当我尝试运行它时出现错误。看起来我没有为 Select-Object 使用正确的格式?谢谢
选择:E 键没有值。在 G:\MarcG\Scripts\AD-Extract.ps1:19 char:17 + $User | 选择@{N='Source KEY'; E=$_.SamAccountName}, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException +fullyQualifiedErrorId : DictionaryKeyMissingValue,Microsoft.PowerShell.Commands.SelectObjectCommand
$users = (get-aduser -LDAPFilter "(&(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))(&(objectCategory=person)(objectClass=user)(!objectClass=inetOrgPerson))(sAMAccountName=s0*)(!sAMAccountName=*-d)(!sAMAccountName=*-e)(!sAMAccountName=*-a)(!Name=Test*)(!Name=v-*)(!employeeID=\00))” -Properties SamAccountName,givenname,sn,enabled,accountexpires,employeeID,employeeNumber,title,company,costcenterID,costcenter,uHALocationName,streetAddress,st,postalcode,mail,xorgid)
ForEach ($User in $Users) {
If ($User.xorgid -ne $Null){
$bytes = $User.xOrgID
$newguid = new-object -TypeName System.Guid -ArgumentList (,$Bytes)
$newguid.ToString()
$User | Select @{N='Source KEY'; E=$_.SamAccountName},
@{N='First Name'; E=$_.givenname},
@{N='Last Name'; E=$_.sn},
@{N='Employee ID'; E=$_.employeeID},
@{N='Job Title'; E=$_.title},
company,
@{N='Cost Center Number'; E=$_.costcenterID}, …Run Code Online (Sandbox Code Playgroud)