I have the attached script to go through many servers in the network and get their share information. Some computers in our network have different names in dns, ex I will query a computername called ComputerA and I will get back data related to ComputerA_New , because somebody changed the computername recently or so
- Currently I am getting column list from the query using "SELECT __Server, ..." query, is it possible for me to also get the passed in computername out as data to find the computer name mismatches?
- The other thing, I started an error handling as below but does not work as I expected. Even though I get multiple errors I can only print one of them., how can I print all the errors?
- And also I would like to link the input computername passed into the powershell script to the error output, I would like to know which computername inputted caused the error, can I do that?
- Also since the error output is long with multilines how can I have computername, errorid, errormessage exported in a format that I can import it back (not sure tab delimited csv export will work here?)
Thank you
$strFileName = "C:\Temp\ShareOut.txt" IF (Test-Path $strFileName){ Remove-Item $strFileName } Try { Get-WmiObject Win32_Share -Filter "Type = 0" -computerName (Get-Content "C:\Temp\ServerList.txt").split(",",[StringSplitOptions]'RemoveEmptyEntries') -ErrorVariable myerror -ErrorAction SilentlyContinue | SELECT __SERVER, Caption, Description, Name, Path, Status | Export-Csv -Delimiter "`t" $strFileName } Catch { Write-Host $myerror.count for ($index = 0; $index -lt $myerror.count; $index++) { Write-Host $myerror[$index].exception } }
Gokhan Varol