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

PowerShell: Find Process ID (PID) Locking a Certain File

Here's a function to kill common processes (Antivirus executable excluded) locking a particular file. This…

PowerShell: Benchmark Disk Speed

Contrary to previous iteration, this version returns an object with multiple properties describing statistical analysis…

How to Install PowerShell Module on An Offlined Computer

# Download the desired module onto a 'jump host' (an intermediary computer that has access…