Advertisement
Guest User

Untitled

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