对于使用PowerShell的实验室,我必须定位特定的OU,并在文本文件中列出以下信息。
DistinguishedName DNSHostName Enabled Name ObjectClass ObjectGUID SamAccountName SID UserPrincipleName
无论如何格式化,我都在网上找到了大量资源,并且不断出错。
这是我的代码:
$ou = 'OU=Testing,OU=Labs,OU=UWEC Computers DC=uwec, DC=edu'
$Computers = Get-ADComputer -Filter '*' -SearchBase $ou
$Computers | foreach {
$_.DNSHostName
} | Out-File -Filepath "C:\Windows\Temp\Lab7.txt"
无论使用哪种语法,我都会不断收到此错误:
Get-ADComputer : The object name has bad syntax At line:1 char:1 + Get-ADComputer -Filter '*' -SearchBase 'OU=Testing,OU=Labs,OU=UWEC Co ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
答案 0 :(得分:1)
您发布的代码与您发布的错误不匹配。但是,最可能导致该错误的原因是您的OU中缺少逗号:
$ou = 'OU=Testing,OU=Labs,OU=UWEC Computers DC=uwec, DC=edu'
# ^right here
将其更改为
$ou = 'OU=Testing,OU=Labs,OU=UWEC Computers,DC=uwec, DC=edu'
问题应该消失了。