Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Try-Catch help

$
0
0

I'm building another report. This time it's getting all the folders in a specific location on multiple computers. I've got it fine working locally and am branching it out to remote computers. I pull the list of computers from AD using QAD-Computer. That works fine. I then use the computer names to build the UNC path for the folder on each remote computer. That's fine too. When I actually use

get-childitem \\Computer\C$\PathImLookingAt

I get one error message or another: "Cannot find path blahblahblah because it does not exist" or "Access Denied". Both are completely expected at this point since either the folder doesn't exist on the computer or my user credentials don't have permission.

Here's what I'm trying to figure out. I want to export the errors into a "error_log" type file, but all the extra fluff that Powershell gives me takes up too much space in the text file. I just want the "+CategoryInfo" part.

ForEach($IndPC in $PCList)
{
  $PCName = ($IndPC).Name
  try {
  Get-ChildItem "\\$PCName\c$\pfx engagement\wm\workpapers"
  }
  catch{
  $_.exception.categoryinfo
  }
}

Any thoughts? Google-fu doesn't seem to be turning up much for me; I'm probably just searching for the wrong thing.


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>