Running powershell script as Admin?


#1

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


#2

Check out the Powershell cookbook:
Cookbook: http://community.opscode.com/cookbooks/powershell
Docs: http://docs.opscode.com/lwrp_powershell.html

and the Windows cookbook.
Cookbook: http://community.opscode.com/cookbooks/windows
Docs: http://docs.opscode.com/lwrp_windows.html

Thanks,
–Charles

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

OPSCODE
CODE CAN
opscode.com Blog Facebook Twitter YouTube

On September 20, 2013 at 3:03:53 PM, Peter Loron (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


#3

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 wrote:

Check out the Powershell cookbook:
Cookbook: http://community.opscode.com/cookbooks/powershell
Docs: http://docs.opscode.com/lwrp_powershell.html

and the Windows cookbook.
Cookbook: http://community.opscode.com/cookbooks/windows
Docs: http://docs.opscode.com/lwrp_windows.html

Thanks,
–Charles

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

OPSCODE
CODE CAN
opscode.com Blog Facebook Twitter YouTube

On September 20, 2013 at 3:03:53 PM, Peter Loron (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


#4

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) 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 wrote:

Check out the Powershell cookbook:
Cookbook: http://community.opscode.com/cookbooks/powershell
Docs: http://docs.opscode.com/lwrp_powershell.html

and the Windows cookbook.
Cookbook: http://community.opscode.com/cookbooks/windows
Docs: http://docs.opscode.com/lwrp_windows.html

Thanks,
–Charles

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

OPSCODE
CODE CAN
opscode.com Blog Facebook Twitter YouTube
On September 20, 2013 at 3:03:53 PM, Peter Loron (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


#5

Have a look at this scriptcenter article on how to run a powershell script
with elevated permissions.
http://gallery.technet.microsoft.com/scriptcenter/63fd1c0d-da57-4fb4-9645-ea52fc4f1dfb/

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 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//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 wrote:

Check out the Powershell cookbook:
Cookbook: http://community.opscode.com/cookbooks/powershell
Docs: http://docs.opscode.com/lwrp_powershell.html

and the Windows cookbook.
Cookbook: http://community.opscode.com/cookbooks/windows
Docs: http://docs.opscode.com/lwrp_windows.html

Thanks,
–Charles

Charles Johnson — Solutions Engineer

(510) 454-9485 – charles@opscode.com – *my: *Linkedinhttp://www.linkedin.com/pub/charles-johnson/1/b38/6a5
Twitter https://twitter.com/chipadeedoodah
OPSCODE

CODE CAN
opscode.com http://www.opscode.com/ Bloghttp://www.opscode.com/blog/
Facebook http://www.facebook.com/opscode Twitterhttp://www.twitter.com/opscode
YouTube http://www.youtube.com/opscode

On September 20, 2013 at 3:03:53 PM, Peter Loron (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