run script block as a specific user with Powershell

后端 未结 3 536
南旧
南旧 2021-01-16 11:12

I am not getting anywhere when using Start-Process / Start-Job cmdlets with -Credential $cred

Problem

I have a service account use in deployment (unattended

3条回答
  •  时光取名叫无心
    2021-01-16 11:49

    Hi this might be an example that might work for you let me know if it does.

    $global:credentials = new-object -typename System.Management.Automation.PSCredential 
    
    
    $job = Start-Job -ScriptBlock {Get-Service} -Credential $credentials
    
    Wait-Job $job
    
    Receive-Job $job
    

提交回复
热议问题