Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Username = "MyUser"
- $Password = "MyPassword"
- $RemoteComputer = 192.168.1.10
- $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password
- $session = New-PSSession -ComputerName $RemoteComputer -Credential $credential
- Invoke-Command -Session $Session {
- #You Need to re-auth to your remote drive now that you're in your session
- #Create a New credential object
- $PSDriveCreds = new-object -typename System.Management.Automation.PSCredential -argumentlist $Using:Username, $Using:Password
- #map a new PSDrive within your session using your new Creds
- New-PSDrive -Name "RemotePSDrive" -PSProvider "FileSystem" -Root "\\RemoteServer\Path\To\Share" -Credential $PSDriveCreds
- #Now you can copy from your PSDrive to the machine you're remoted to
- Copy-Item RemotePSDrive:\Myfile.ext C:\Local\Path
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement