copy-item With Alternate Credentials

后端 未结 12 2061
长情又很酷
长情又很酷 2020-12-01 05:29

I\'m using the CTP of powershell v2. I have a script written that needs to go out to various network shares in our dmz and copy some files. However, the issue I have is that

12条回答
  •  一生所求
    2020-12-01 05:40

    Since PowerShell doesn't support "-Credential" usage via many of the cmdlets (very annoying), and mapping a network drive via WMI proved to be very unreliable in PS, I found pre-caching the user credentials via a net use command to work quite well:

    # cache credentials for our network path
    net use \\server\C$ $password /USER:$username
    

    Any operation that uses \\server\C$ in the path seems to work using the *-item cmdlets.

    You can also delete the share when you're done:

    net use \\server\C$ /delete
    

提交回复
热议问题