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

Basic HTML and HTML5: Link to Internal Sections of a Page with Anchor Elements

<h2>Demo</h2><main><a href="#footer">Jump to Bottom</a><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."><p>Kitty ipsum dolor…

PowerShell: Check RPC Reachability of Remote Computer

# This is an ancient script that would work with PowerShell versions 2 to 5,…

Installing DotNet 3.5 on Windows with Restricted Internet Access

# Set Windows Source files # Assuming that a Windows ISO / DVD Rom have…