Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell output and formatting

Tags:

powershell

I have something I have put together to scan computers on my network and look for certain chrome extensions.

It works and displays the information in the PowerShell console. But if it finds the extension in multiple user profiles on a machine it creates a giant blob of information instead of separating it into multiple lines and I would like to have this output to a txt or csv file:

$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 
   }
like image 721
Joe Clark Avatar asked Feb 27 '26 02:02

Joe Clark


1 Answers

You probably want to enumerate the return value of the Get-ChildItem cmdlet:

Get-ChildItem $BetterNet | ForEach-Object {
    write-host BetterNet found on: 
    Write-Host "     "$_ 
    write-host 
}
like image 173
Martin Brandl Avatar answered Mar 02 '26 15:03

Martin Brandl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!