Permission errors in PowerShell

前端 未结 4 481
臣服心动
臣服心动 2020-12-16 09:24

I am new to PowerShell. When trying to write a simple script that deletes the contents of a folder and then fills it with files copied from a different folder, I always get

相关标签:
4条回答
  • 2020-12-16 09:43

    Have you try :

    remove-item D:\path_A\* -recurse -force
    
    0 讨论(0)
  • 2020-12-16 09:46

    After this error (and assuming at that point in it the most recent error):

    $error[0] | fl * -force
    

    will expand the details of the error and exception. That should give you more information.

    Another thing to do is to switch on verbose logging

    $VerbosePreference = "Continue"
    

    to get more details about specifically what operation is being performed when the error occurs.

    Finally PowerShell ISE includes a debugger which allows you to step through your script.

    0 讨论(0)
  • 2020-12-16 09:48

    Is UAC enabled? If so try running your PowerShell session as 'Administrator'. It really looks like you don't have permission to delete the objects.

    We have very restrictive security policies where I work and users not familiar with UAC get burned all the time.

    0 讨论(0)
  • 2020-12-16 09:52

    In addition to reasons mentioned in the above posts, i've observed that "Access Denied" error is thrown when the file is being accessed by a separate process (In my case, i had to stop the server before Rename-Item could be run successfully).

    0 讨论(0)
提交回复
热议问题