Advertisement
Guest User

Untitled

a guest
May 11th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1.  
  2. $DemoUser = 'Domain\username'
  3. $DemoPass = 'complexpassword'
  4. $Command = "ECHO 'Hello world'; WhoAmi;"
  5. $StdOutLogFile = "$env:windir\temp\PowerShellElevatedStdOut.log"
  6.  
  7. $SecurePassword = ConvertTo-SecureString $DemoPass -AsPlainText -Force
  8. $Credential = New-Object System.Management.Automation.PSCredential $DemoUser, $securePassword
  9.  
  10. "Running '$Command' as current user"
  11. Start-Process Powershell.exe -NoNewWindow -ArgumentList "-Command $Command" -RedirectStandardOutput $StdOutLogFile -Wait
  12. Get-Content -Path $StdOutLogFile #Retrieve the output from the external process
  13.  
  14. "Running '$Command' as $DemoUser"
  15. Start-Process Powershell.exe -NoNewWindow -ArgumentList "-Command $Command" -RedirectStandardOutput $StdOutLogFile -Wait -Credential $Credential -WorkingDirectory 'C:\Windows\System32'
  16. Get-Content -Path $StdOutLogFile #Retrieve the output from the external process
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement