簡體   English   中英

使用 PowerShell 列出 OU 中所有計算機的信息

[英]Listing information for all computers in an OU using PowerShell

對於使用 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

您發布的代碼與您發布的錯誤不匹配。 但是,錯誤的最可能原因是您的 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'

問題應該會消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM