none
How to capture and then report locations that get-childitem shows as access denied? RRS feed

  • Question

  • I am trying to work on a simple script (what I thought would be simple) that uses get-childitem to recurse through a specific directory and then reports the locations where access has been denied and I cannot seem to get this down.
    Thursday, May 23, 2019 12:07 AM

Answers

  • Here's a start.  $err should give you the info you need.  If you pipe it to format-list, you have to use -force.

    get-childitem -recurse -errorvariable err
    $err | select *

    Thursday, May 23, 2019 12:53 PM

All replies

  • We do not write ready to use code on request. If you're looking for prewritten scripts you should search the Microsoft Technet Script Gallery or the PowershellGallery.

    You might start with reading about error handling with about_try_catch_finaly.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    Thursday, May 23, 2019 12:41 AM
  • The error message contains the file/folder name.  Just look at the whole message.

    Start by learning how to use help. The following will teach you how to use help:

    help help

    Now use what you have learned to get help:

    help Get-ChildItem -ShowWindow


    \_(ツ)_/

    Thursday, May 23, 2019 12:55 AM
    Moderator
  • Here's a start.  $err should give you the info you need.  If you pipe it to format-list, you have to use -force.

    get-childitem -recurse -errorvariable err
    $err | select *

    Thursday, May 23, 2019 12:53 PM
  • ... really? ... :-/

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Thursday, May 23, 2019 1:13 PM
  • ... really? ... :-/

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    Just kidding;)

    \_(ツ)_/

    Thursday, May 23, 2019 1:18 PM
    Moderator
  • I ran the help and somehow missed the -ErrorVariable parameter.

    This seems to do what I need.

    Clear-Variable -Name Err

    Get-ChildItem -Depth 2 -Recurse -ErrorVariable Err -ErrorAction SilentlyContinue | Out-Null

    Write-Warning -Message "Total Errors: $($Err.Count)"

    $Separators = (".")

    $Err = [String]$Err

    $Err.Split($Separators).TrimStart()

    Thanks for your help.


    Friday, May 24, 2019 4:18 PM
  • ErrorVariable" is something that we learn in PowerShell kindergarten.  It is fundamental knowledge to all of PowerShell.  This is one reason I coax all pre-kindergarten kids to actually take the time to learn PowerShell.

    Alas.  Children really hate to do their schoolwork. 


    \_(ツ)_/

    Friday, May 24, 2019 5:11 PM
    Moderator
  • Someone can't take a little teasing.  Am I getting too close to home.

    Cool out.  You just need to do a little more learning of the basics if you want to play with the big boys.

    P.S. - trained many techs and got the same whining from some until they knocked it off an started to take things seriously.

    If you go back to the beginning and learn PS carefully you will be surprised at what you will learn. 

    I also kick myself the same way and have gone back to beginnings to relearn may technologies.  It is a just a requirement of the job (and life).


    \_(ツ)_/

    Friday, May 24, 2019 5:26 PM
    Moderator
  • I also kick myself the same way and have gone back to beginnings to relearn many technologies.  It is a just a requirement of the job (and life).

    You have been guessing a lot.  Now you have some ideas.  Lock them down by relearning the facts.  It will change your whole understanding of computer automation and coding. You will also start to understand many really cool things about PowerShell.

    I am sorry that teasing you about the "ErrorVariable" was upsetting.  Too bad you couldn't see my face when I posted it.

    Good luck.


    \_(ツ)_/

    Friday, May 24, 2019 5:37 PM
    Moderator