PowerShell Management Series (35) PowerShell operations run scripts with administrator privileges

Source: Internet
Author: User

-----provide ad\exchange\lync\sharepoint\crm\sc\o365 and other Microsoft product implementation and outsourcing, qq:185426445. Phone 18666943750

Scenario: Win10 or non-administrator permissions when running the command line, prompt for no permissions, such as

650) this.width=650; "Width=" "height=" 153 "title=" 1.png "style=" WIDTH:725PX;HEIGHT:246PX; "alt=" Wkiol1gi5gabq12saaaf6nxdprg670.png-wh_50 "src=" http://s2.51cto.com/wyfs02/M01/89/22/ Wkiol1gi5gabq12saaaf6nxdprg670.png-wh_500x0-wm_3-wmp_4-s_750550442.png "/>

We can right-click PowerShell, run with administrator privileges, or the scheduled task is set to run with administrator privileges, in fact we have a more efficient way to direct the right to run the script, for example, enter the user name and password,

Invoke-command-scriptblock {Ipconfig/registerdns}-computername desktop-jq6usg3-credential (Get-Credential)

650) this.width=650; "Width=" "height=" 309 "title=" 1.png "style=" Width:724px;height:523px;float:none; "alt=" Wkiom1gi52rqm4peaaeyfwyx8l8840.png-wh_50 "src=" http://s1.51cto.com/wyfs02/M00/89/25/ Wkiom1gi52rqm4peaaeyfwyx8l8840.png-wh_500x0-wm_3-wmp_4-s_939684494.png "/>

The result runs as follows, and the command executes successfully without prompting for insufficient permissions.

650) this.width=650; "Width=" 501 "height=" 237 "title=" 2.png "style=" Width:724px;height:443px;float:none; "alt=" Wkiol1gi52ucfaybaabxmofqhli685.png-wh_50 "src=" http://s1.51cto.com/wyfs02/M00/89/22/ Wkiol1gi52ucfaybaabxmofqhli685.png-wh_500x0-wm_3-wmp_4-s_101611085.png "/>

If you do not need to enter a user name and password, and save the command to the. PS1 script, as follows:

$UserName = "Administrator" #定义管理员账户名称
$Password = convertto-securestring Aa12345678-asplaintext–force
$cred = New-object System.Management.Automation.PSCredential ($UserName, $Password)
Invoke-command-credential $cred-command {C:\Users\Terry.zhou\Desktop\host.ps1}-computername desktop-jq6usg3

650) this.width=650; "Width=" height= "307" title= "QQ picture 20161020235431.png" style= "WIDTH:723PX;HEIGHT:534PX;" alt= "Wkiol1gi6ntsevyraadiqmbnige203.png-wh_50" src= "http://s3.51cto.com/wyfs02/M00/89/22/ Wkiol1gi6ntsevyraadiqmbnige203.png-wh_500x0-wm_3-wmp_4-s_1118938539.png "/>

650) this.width=650; "Width=" 502 "height=" 273 "title=" 1.png "style=" width:718px;height:431px; "alt=" Wkiom1gi6s2tydmzaaandqpbxqk130.png-wh_50 "src=" http://s4.51cto.com/wyfs02/M02/89/25/ Wkiom1gi6s2tydmzaaandqpbxqk130.png-wh_500x0-wm_3-wmp_4-s_2146441999.png "/>



This article is from the "Zhou Ping Microsoft Technology Exchange Platform" blog, please be sure to keep this source http://yuntcloud.blog.51cto.com/1173839/1864075

PowerShell Management Series (35) PowerShell operations run scripts with administrator privileges

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.