Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $DemoUser = 'Domain\username'
- $DemoPass = 'complexpassword'
- $Command = "ECHO 'Hello world'; WhoAmi;"
- $StdOutLogFile = "$env:windir\temp\PowerShellElevatedStdOut.log"
- $SecurePassword = ConvertTo-SecureString $DemoPass -AsPlainText -Force
- $Credential = New-Object System.Management.Automation.PSCredential $DemoUser, $securePassword
- "Running '$Command' as current user"
- Start-Process Powershell.exe -NoNewWindow -ArgumentList "-Command $Command" -RedirectStandardOutput $StdOutLogFile -Wait
- Get-Content -Path $StdOutLogFile #Retrieve the output from the external process
- "Running '$Command' as $DemoUser"
- Start-Process Powershell.exe -NoNewWindow -ArgumentList "-Command $Command" -RedirectStandardOutput $StdOutLogFile -Wait -Credential $Credential -WorkingDirectory 'C:\Windows\System32'
- Get-Content -Path $StdOutLogFile #Retrieve the output from the external process
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement