MSBuild calling Powershell with credentials

后端 未结 2 1243
闹比i
闹比i 2021-01-28 10:03

I\'m trying to deploy a windows service using an MSBuild script that runs a Powershell command.

The MSBuild script deploys the files I need and the PowerShell script wi

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 10:23

    Maybe something like this?

    $Creds  =   $host.ui.PromptForCredential("Need credentials", "Please enter username/password with proper rights on objects to manage.`r`n`r`nExample: AD-Domain\username", $env:userdomain + "\" + $env:username, "")
    $IPAddressHere = "192.168.0.1"
    powershell.exe -NonInteractive -executionpolicy Unrestricted -command "& {Invoke-Command -ComputerName $IPAddressHere -FilePath 'C:\theScriptFileName.ps1' -credentials $creds}" 
    

提交回复
热议问题