Posted On June 17, 2020

PowerShell: Run PowerShell As Another User

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Run PowerShell As Another User
# Set credential
$adminUsername='domain\adminDude'
$adminPassword='whatpassword?'
$GLOBAL:adminCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUsername,$(ConvertTo-securestring $adminPassword -AsPlainText -Force)

# Test pinging some domain
$domain='google.com'
$testJob=Start-Job -ScriptBlock {
    param($x)
    ping $x
} -Credential $adminCredential -Args $domain
Wait-Job $testJob|out-null 
$jobResult=Receive-Job $testJob

$jobResult|write-host

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Default Nginx Installation on Centos 7

NGINX as HTTP / HTTPS Proxysudo yum install epel-releasesudo yum install nginxsudo systemctl start nginxsudo…

CSS: Variables & Simple Animation

CSS can mimic other interpreted programming languages by enabling features such as variables. The limitation…

Sample Forth Shift Script

REM Daily Batch for Fourth Shiftrem E:\FShift\cabsauto\timeout 14400rem E:\FShift\cabsauto\timeout 7200rem E:\FShift\cabsauto\timeout 7200rem E:\FShift\cabsauto\timeout 7200rem E:\FShift\cabsauto\timeout…