# Running powershell script as Admin?

**URL:** <https://discourse.chef.io/t/running-powershell-script-as-admin/4481>\
**Category:** Chef Infra (archive)\
**Created:** [September 20, 2013, 10:03pm UTC](https://discourse.chef.io/t/running-powershell-script-as-admin/4481 "2013-09-20T22:03:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Loron](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/peter_loron/32/338_2.png) [@Peter\_Loron](https://discourse.chef.io/u/Peter_Loron)\
**Post date:** [September 20, 2013, 10:03pm UTC](https://discourse.chef.io/t/running-powershell-script-as-admin/4481/1 "2013-09-20T22:03:38Z")

</div>

I need to run a bit of powershell code in a recipe with elevated privs. Specifically, I need to run ‘enable-psremoting -force’.

By hand, I’d RDP to the box, and start a shell as Administrator and be done.

How can I duplicate this in a chef recipe?

Thanks.

-Pete

---

<div class="post-metadata">

**Author:** ![Charles\_Johnson1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/charles_johnson1/32/210_2.png) [@Charles\_Johnson1](https://discourse.chef.io/u/Charles_Johnson1)\
**Post date:** [September 20, 2013, 11:13pm UTC](https://discourse.chef.io/t/running-powershell-script-as-admin/4481/2 "2013-09-20T23:13:11Z")

</div>

Check out the Powershell cookbook:  
Cookbook: [http://community.opscode.com/cookbooks/powershell](http://community.opscode.com/cookbooks/powershell)  
Docs: [http://docs.opscode.com/lwrp\_powershell.html](http://docs.opscode.com/lwrp_powershell.html)

and the Windows cookbook.  
Cookbook: [http://community.opscode.com/cookbooks/windows](http://community.opscode.com/cookbooks/windows)  
Docs: [http://docs.opscode.com/lwrp\_windows.html](http://docs.opscode.com/lwrp_windows.html)

Thanks,  
–Charles

Charles Johnson — Solutions Engineer  
(510) 454-9485 – [charles@opscode.com](mailto:charles@opscode.com) – my: Linkedin Twitter

OPSCODE  
CODE CAN  
[opscode.com](http://opscode.com) Blog Facebook Twitter YouTube

On September 20, 2013 at 3:03:53 PM, Peter Loron ([peterl@standingwave.org](mailto:peterl@standingwave.org)) wrote:

I need to run a bit of powershell code in a recipe with elevated privs. Specifically, I need to run ‘enable-psremoting -force’.

By hand, I’d RDP to the box, and start a shell as Administrator and be done.

How can I duplicate this in a chef recipe?

Thanks.

-Pete

---

<div class="post-metadata">

**Author:** ![Peter\_Loron](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/peter_loron/32/338_2.png) [@Peter\_Loron](https://discourse.chef.io/u/Peter_Loron)\
**Post date:** [September 23, 2013, 5:58pm UTC](https://discourse.chef.io/t/running-powershell-script-as-admin/4481/3 "2013-09-23T17:58:25Z")

</div>

Hi. Charles. Yes, already looked there. Those show how to run commands in powershell, which is working fine. However, I need to run some commands with admin rights (run as Administrator). In the desktop, I can just do with with a right-click when launching Powershell. How do I duplicate this via Chef? Our boxes do not have local admin enabled, so I can't just use that user.

-Pete

On Sep 20, 2013, at 4:13 PM, Charles Johnson [charles@opscode.com](mailto:charles@opscode.com) wrote:

> Check out the Powershell cookbook:  
> Cookbook: [http://community.opscode.com/cookbooks/powershell](http://community.opscode.com/cookbooks/powershell)  
> Docs: [http://docs.opscode.com/lwrp\_powershell.html](http://docs.opscode.com/lwrp_powershell.html)
> 
> and the Windows cookbook.  
> Cookbook: [http://community.opscode.com/cookbooks/windows](http://community.opscode.com/cookbooks/windows)  
> Docs: [http://docs.opscode.com/lwrp\_windows.html](http://docs.opscode.com/lwrp_windows.html)
> 
> Thanks,  
> --Charles
> 
> Charles Johnson — Solutions Engineer  
> (510) 454-9485 – [charles@opscode.com](mailto:charles@opscode.com) – my: Linkedin Twitter
> 
> OPSCODE  
> CODE CAN  
> [opscode.com](http://opscode.com) Blog Facebook Twitter YouTube
> 
> On September 20, 2013 at 3:03:53 PM, Peter Loron ([peterl@standingwave.org](mailto:peterl@standingwave.org)) wrote:
> 
> > I need to run a bit of powershell code in a recipe with elevated privs. Specifically, I need to run 'enable-psremoting -force'.
> > 
> > By hand, I'd RDP to the box, and start a shell as Administrator and be done.
> > 
> > How can I duplicate this in a chef recipe?
> > 
> > Thanks.
> > 
> > -Pete

---

<div class="post-metadata">

**Author:** ![Tim\_Green](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@Tim\_Green](https://discourse.chef.io/u/Tim_Green)\
**Post date:** [September 23, 2013, 7:48pm UTC](https://discourse.chef.io/t/running-powershell-script-as-admin/4481/4 "2013-09-23T19:48:29Z")

</div>

Could you clarify what you mean by “right-click when launching Powershell”. I think this is the equivalent of the runas.exe command? If that’s the case, I would suggest right-click/runas to execute cmd.exe, then run the chef-client from here.

On September 23, 2013 at 1:58:38 PM, Peter Loron ([peterl@standingwave.org](mailto:peterl@standingwave.org)) wrote:

Hi. Charles. Yes, already looked there. Those show how to run commands in powershell, which is working fine. However, I need to run some commands with admin rights (run as Administrator). In the desktop, I can just do with with a right-click when launching Powershell. How do I duplicate this via Chef? Our boxes do not have local admin enabled, so I can’t just use that user.

-Pete

On Sep 20, 2013, at 4:13 PM, Charles Johnson [charles@opscode.com](mailto:charles@opscode.com) wrote:

Check out the Powershell cookbook:  
Cookbook: [http://community.opscode.com/cookbooks/powershell](http://community.opscode.com/cookbooks/powershell)  
Docs: [http://docs.opscode.com/lwrp\_powershell.html](http://docs.opscode.com/lwrp_powershell.html)

and the Windows cookbook.  
Cookbook: [http://community.opscode.com/cookbooks/windows](http://community.opscode.com/cookbooks/windows)  
Docs: [http://docs.opscode.com/lwrp\_windows.html](http://docs.opscode.com/lwrp_windows.html)

Thanks,  
–Charles

Charles Johnson — Solutions Engineer  
(510) 454-9485 – [charles@opscode.com](mailto:charles@opscode.com) – my: Linkedin Twitter

OPSCODE  
CODE CAN  
[opscode.com](http://opscode.com) Blog Facebook Twitter YouTube  
On September 20, 2013 at 3:03:53 PM, Peter Loron ([peterl@standingwave.org](mailto:peterl@standingwave.org)) wrote:

I need to run a bit of powershell code in a recipe with elevated privs. Specifically, I need to run ‘enable-psremoting -force’.

By hand, I’d RDP to the box, and start a shell as Administrator and be done.

How can I duplicate this in a chef recipe?

Thanks.

-Pete

---

<div class="post-metadata">

**Author:** ![Mat\_Davies](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/mat_davies/32/446_2.png) [@Mat\_Davies](https://discourse.chef.io/u/Mat_Davies)\
**Post date:** [September 24, 2013, 9:33am UTC](https://discourse.chef.io/t/running-powershell-script-as-admin/4481/5 "2013-09-24T09:33:29Z")

</div>

Have a look at this scriptcenter article on how to run a powershell script  
with elevated permissions.

> **[Browse code samples](https://learn.microsoft.com/en-us/samples/browse/?redirectedfrom=TechNet-Gallery)**
>
> Get started with Microsoft developer tools and technologies. Explore our samples and discover the things you can build.

there are two other ways I can thing of doing it if you run as the bultin  
administrator you will not have this issue (that may not be possible  
though), the worst solution would be to turn of the UAC protection.

-Mat

On 23 September 2013 20:48, Tim Green [tgreen@opscode.com](mailto:tgreen@opscode.com) wrote:

> Could you clarify what you mean by "right-click when launching  
> Powershell". I think this is the equivalent of the runas.exe command? If  
> that's the case, I would suggest right-click/runas to execute cmd.exe, then  
> run the chef-client from here.
> 
> On September 23, 2013 at 1:58:38 PM, Peter Loron ([peterl@standingwave.org](mailto:peterl@standingwave.org)//peterl@standingwave.org)  
> wrote:
> 
> Hi. Charles. Yes, already looked there. Those show how to run commands in  
> powershell, which is working fine. However, I need to run some commands  
> with admin rights (run as Administrator). In the desktop, I can just do  
> with with a right-click when launching Powershell. How do I duplicate this  
> via Chef? Our boxes do not have local admin enabled, so I can't just use  
> that user.
> 
> -Pete
> 
> On Sep 20, 2013, at 4:13 PM, Charles Johnson [charles@opscode.com](mailto:charles@opscode.com) wrote:
> 
> Check out the Powershell cookbook:  
> Cookbook: [http://community.opscode.com/cookbooks/powershell](http://community.opscode.com/cookbooks/powershell)  
> Docs: [http://docs.opscode.com/lwrp\_powershell.html](http://docs.opscode.com/lwrp_powershell.html)
> 
> and the Windows cookbook.  
> Cookbook: [http://community.opscode.com/cookbooks/windows](http://community.opscode.com/cookbooks/windows)  
> Docs: [http://docs.opscode.com/lwrp\_windows.html](http://docs.opscode.com/lwrp_windows.html)
> 
> Thanks,  
> --Charles
> 
> _Charles Johnson_ — Solutions Engineer
> 
> (510) 454-9485 – [charles@opscode.com](mailto:charles@opscode.com) – \*my: \*Linkedin[http://www.linkedin.com/pub/charles-johnson/1/b38/6a5](http://www.linkedin.com/pub/charles-johnson/1/b38/6a5)  
> Twitter [https://twitter.com/chipadeedoodah](https://twitter.com/chipadeedoodah)  
> OPSCODE
> 
> CODE CAN  
> _[opscode.com](http://opscode.com) [http://www.opscode.com/](http://www.opscode.com/)_ Blog[http://www.opscode.com/blog/](http://www.opscode.com/blog/)  
> Facebook [http://www.facebook.com/opscode](http://www.facebook.com/opscode) Twitter[http://www.twitter.com/opscode](http://www.twitter.com/opscode)  
> YouTube [http://www.youtube.com/opscode](http://www.youtube.com/opscode)
> 
> On September 20, 2013 at 3:03:53 PM, Peter Loron ([peterl@standingwave.org](mailto:peterl@standingwave.org))  
> wrote:
> 
> I need to run a bit of powershell code in a recipe with elevated privs.  
> Specifically, I need to run 'enable-psremoting -force'.
> 
> By hand, I'd RDP to the box, and start a shell as Administrator and be  
> done.
> 
> How can I duplicate this in a chef recipe?
> 
> Thanks.
> 
> -Pete
