Error Handling on Network Drives

This topic contains 3 replies, has 3 voices, and was last updated by  notarat 4 years, 9 months ago.

  • Author
  • #10115


    I scan our network drives routinely to generate usage statistics. Sometimes I encounter situations where a user acidentally removed my permissions

    Note: Giving users Full Control is not my call and it cannot be changed

    I created a litle script that recursively looks through the network drive to record those denied permissions. It works fine on my local D and C drives, but is not recording the error when run against a network drive. The fields in $error are the same regardless of the drive scanned so I am unsure what I'm missing.

    Here's the code

    gci '\\Server6\share$\site' -recurse -errorvariable strOOPS
    If ($stroops -ne $null)
        add-content -value $erec c:\outputfiles\DENIED.TXT
        Write-host "No Errors"
  • #10118

    Rob Simmers

    Have you tried a standard Try\Catch?

    try {
        gci '\\Server6\share$\site' -recurse 
    catch {
        "Error occurred: {0}" -f $_.Exception.Message
  • #10124

    Richard Siddaway

    You'll need to set the erroraction to stop on get-childitem

  • #10266


    I managed to get it working pretty well after some futzing around with it.

    write-host -NoNewline "Enter UNC Path or Drive, such as \\fileserver10\region\Site\ or S:\ or Z:\ "                                                                     
    gci $vStartingPath -recurse|where{$_.psiscontainer -eq $True} | foreach {
      $path = $_
      $_|get-acl|select mode
    #  $_|get-acl|select pschildname
      $path.FullName | Out-File c:\outputfiles\PermDenied.txt -Append

    It isn't the fastest tool to use but it is the only one I have to check permissions so I'm not going to complain.

You must be logged in to reply to this topic.