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: Deploy Choco Apps

Deployment Instructions: Create a batch file with this content to call this PowerShell Script @echo…

PowerShell: Creating Clustered File Shares

# Define Destination Mount Points and UNC Paths $arr=@{} $arr["from"] = @{}; $arr["to"] = @{}…

PowerShell Commands to Install the NTFSSecurity Module

Background information:- NTFS code is hosted on Github: https://codeload.github.com/raandree/NTFSSecurity/zip/refs/heads/master- Find module path with this command:…