Mahesh
Mahesh

Reputation: 97

I want run PowerShell commands using administrator with normal PowerShell user

I want execute following command without opening admin PowerShell prompt.It should be execute on normal prompt. like we are sudo useradd <username> in Linux.

Enable-PSRemoting; 
Set-Item wsman:\\localhost\\client\\trustedhosts $hostIP -Force;
Restart-Service WinRM

I am going integrate this code into C#. Please help me to solve this issue.

Upvotes: 0

Views: 261

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200493

What you're asking is not possible directly from a PowerShell script, at least as far as I know. What you can do is create a scheduled task running that script with admin privileges, and then invoke the scheduled task as a normal user.

Upvotes: 2

TobyU
TobyU

Reputation: 3918

That is not possible. Allowing that would be a major security issue in Windows.

Upvotes: 1

Related Questions