Làm thế nào tôi có thể nhận tất cả điều này không chỉ xuất trên màn hình mà còn lưu vào tệp văn bản ở định dạng CSV?Hiển thị đầu ra trên màn hình và trong tệp trong PowerShell
$OUs = Get-ADObject -LDAPFilter "(objectCategory=organizationalUnit)" `
-SearchBase "OU=GA,OU=EAST,DC=corp,DC=chm,DC=com" | Select distinguishedName
ForEach ($OU In $OUs)
{
$OU.distinguishedName
Get-ADComputer -SearchBase $OU.distinguishedName -SearchScope OneLevel `
-Filter * | Select Name
}
Tôi đã thử
$OUs = Get-ADObject -LDAPFilter "(objectCategory=organizationalUnit)" `
-SearchBase "OU=GA,OU=EAST,DC=corp,DC=chartercom,DC=com" | Select distinguishedName
ForEach ($OU In $OUs)
{
$OU.distinguishedName
Get-ADComputer -SearchBase $OU.distinguishedName -SearchScope OneLevel `
-Filter * | Select Name
} | | export-CSV c:\temp\outfile.csv –noType
Và nhiều định dạng khác, nhưng tôi luôn luôn nhận được lỗi:
An empty pipe element is not allowed.
đó mang lại cho tôi những lỗi tương tự – Ron
$ OU = Get-ADObject -LDAPFilter "(objectCategory = organizationalUnit)" ' -SearchBase "OU = GA, OU = EAST, DC = corp, DC = chm, DC = com "| Chọn phân biệtName ForEach ($ OU trong $ OUs) { $ OU.distinguishedName Nhận-ADComputer -SearchBase $ OU.distinguishedName -SearchScope OneLevel ' -Filter * | Chọn Tên } Tee-Object -file c: \ temp \ outfile.txt – Ron
Chỉ ** pipe ** nó vào lệnh 'Tee-Object'. Xem cập nhật của tôi. –