powershell输出到CSV

时间:2016-12-22 15:05:30

标签: powershell-v4.0

我想将此powershell的输出发送到文件,目前它输出到屏幕,我尝试添加各种管道到文件命令,但它用数字和屏幕上的原始内容填充文件

$strFilter = "(&(objectCategory=Group)(|(groupType=2)(groupType=4)(groupType=8)))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$objSearcher.PropertiesToLoad.Add("cn") | Out-Null
$objSearcher.PropertiesToLoad.Add("member") | Out-Null

$($colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults){
    $objItem = $objResult.Properties;
    Write-Output $objItem.cn
    foreach ($objMember in $objItem.member) {
        Write-Output "   $objMember" 
    } 
}

0 个答案:

没有答案