Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. Import-Module bitstransfer
  2. $cred = Get-Credential
  3. $sourcePath = \serverexamplefile.txt
  4. $destPath = C:LocalDestination
  5. Start-BitsTransfer -Source $sourcePath -Destination $destPath -Credential $cred
  6.  
  7. $cred = Get-Credential
  8. $networkCred = $cred.GetNetworkCredential()
  9. net use \serverexample $networkCred.Password /USER:$networkCred.UserName
  10. Copy-Item \serverexamplefile.txt C:LocalDestination
  11.  
  12. # cache credentials for our network path
  13. net use \serverC$ $password /USER:$username
  14.  
  15. net use \serverC$ /delete
  16.  
  17. PS > New-PSDrive -Name J -PSProvider FileSystem -Root \server001sharename -Credential mydomaintravisj -Persist
  18.  
  19. $Source = "C:Downloadsmyfile.txt"
  20. $Dest = "\10.149.12.162c$skumar"
  21. $Username = "administrator"
  22. $Password = ConvertTo-SecureString "Complex_Passw0rd" -AsPlainText -Force
  23. $mycreds = New-Object System.Management.Automation.PSCredential($Username, $Password)
  24.  
  25. New-PSDrive -Name J -PSProvider FileSystem -Root $Dest -Credential $mycreds -Persist
  26. Copy-Item -Path $Source -Destination "J:myfile.txt"
  27.  
  28. psexec.exe /accepteula /h /u user /p pwd cmd /c "echo. | powershell.exe -File script.ps1"
  29.  
  30. $plaintext_password_file = 'C:plaintext.txt' # Stores the password in plain text - only used once, then deleted
  31. $encryted_password_file = 'C:copy_pass.txt' # Stores the password in "safe" encrypted form - used for subsequent runs of the script
  32. # - can only be decrypted by the windows user that wrote it
  33. $file_copy_user = 'OURDOMAINA_User'
  34.  
  35. # Check to see if there is a new plaintext password
  36. if (Test-Path $plaintext_password_file)
  37. {
  38. # Read in plaintext password, convert to a secure-string, convert to an encrypted-string, and write out, for use later
  39. get-content $plaintext_password_file | convertto-securestring -asplaintext -force | convertfrom-securestring | out-file $encryted_password_file
  40. # Now we have encrypted password, remove plain text for safety
  41. Remove-Item $plaintext_password_file
  42. }
  43.  
  44.  
  45. # Read in the encrypted password, convert to a secure-string
  46. $pass = get-content $encryted_password_file | convertto-securestring
  47.  
  48. # create a credential object for the other user, using username and password stored in secure-string
  49. $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $file_copy_user,$pass
  50.  
  51. # Connect to network file location as the other user and map to drive J:
  52. New-PSDrive -Name J -PSProvider FileSystem -Root "\networkfile_directory" -Credential $credentials
  53.  
  54. # Copy the file to J:
  55. Copy-Item -Force -Verbose -Path "C:a_file.txt" -Destination "J:"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement