Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module bitstransfer
- $cred = Get-Credential
- $sourcePath = \serverexamplefile.txt
- $destPath = C:LocalDestination
- Start-BitsTransfer -Source $sourcePath -Destination $destPath -Credential $cred
- $cred = Get-Credential
- $networkCred = $cred.GetNetworkCredential()
- net use \serverexample $networkCred.Password /USER:$networkCred.UserName
- Copy-Item \serverexamplefile.txt C:LocalDestination
- # cache credentials for our network path
- net use \serverC$ $password /USER:$username
- net use \serverC$ /delete
- PS > New-PSDrive -Name J -PSProvider FileSystem -Root \server001sharename -Credential mydomaintravisj -Persist
- $Source = "C:Downloadsmyfile.txt"
- $Dest = "\10.149.12.162c$skumar"
- $Username = "administrator"
- $Password = ConvertTo-SecureString "Complex_Passw0rd" -AsPlainText -Force
- $mycreds = New-Object System.Management.Automation.PSCredential($Username, $Password)
- New-PSDrive -Name J -PSProvider FileSystem -Root $Dest -Credential $mycreds -Persist
- Copy-Item -Path $Source -Destination "J:myfile.txt"
- psexec.exe /accepteula /h /u user /p pwd cmd /c "echo. | powershell.exe -File script.ps1"
- $plaintext_password_file = 'C:plaintext.txt' # Stores the password in plain text - only used once, then deleted
- $encryted_password_file = 'C:copy_pass.txt' # Stores the password in "safe" encrypted form - used for subsequent runs of the script
- # - can only be decrypted by the windows user that wrote it
- $file_copy_user = 'OURDOMAINA_User'
- # Check to see if there is a new plaintext password
- if (Test-Path $plaintext_password_file)
- {
- # Read in plaintext password, convert to a secure-string, convert to an encrypted-string, and write out, for use later
- get-content $plaintext_password_file | convertto-securestring -asplaintext -force | convertfrom-securestring | out-file $encryted_password_file
- # Now we have encrypted password, remove plain text for safety
- Remove-Item $plaintext_password_file
- }
- # Read in the encrypted password, convert to a secure-string
- $pass = get-content $encryted_password_file | convertto-securestring
- # create a credential object for the other user, using username and password stored in secure-string
- $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $file_copy_user,$pass
- # Connect to network file location as the other user and map to drive J:
- New-PSDrive -Name J -PSProvider FileSystem -Root "\networkfile_directory" -Credential $credentials
- # Copy the file to J:
- Copy-Item -Force -Verbose -Path "C:a_file.txt" -Destination "J:"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement