2017-01-26 227 views
3

我有一些东西我放在一起扫描我的网络上的计算机,并寻找某些铬扩展。PowerShell输出和格式化

它工作并在PowerShell控制台中显示信息。但是,如果它发现扩展在多个用户配置的机器上它创建的信息,一个巨大的一滴,而不是将其分离成多行的,我想有这个输出到一个txt或者csv文件:

$hostnamestxt = "Server with list of computers" 
$computers = get-content “$hostnamestxt” 

write-host Scanning........ 


foreach($computer in $computers){ 
$BetterNet = "\\$computer\c$\users\*\AppData\Local\Google\Chrome\User Data\Default\Extensions\gjknjjomckknofjidppipffbpoekiipm" 

if (Test-Path $BetterNet) { 
    $a = Get-ChildItem $BetterNet 
    write-host BetterNet found on: 
    Write-Host "  "$a 
    write-host 
    } 

回答

2

你可能想枚举Get-ChildItem cmdlet的返回值:

Get-ChildItem $BetterNet | ForEach-Object { 
    write-host BetterNet found on: 
    Write-Host "  "$_ 
    write-host 
} 
+0

这个工作在分手数据的斑点大。非常感谢你。如何将它输出到文件? –

+0

不要使用'Write-Host' cmdlet,而要查看'Set-Content'和'Add-Content' cmdlet。请注意编码('-Encodign'参数) –

+0

完美谢谢。 –