Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Runas when running Powershell scripts?

272 views
Skip to first unread message

Snowmizer

unread,
Apr 22, 2008, 2:25:04 PM4/22/08
to
I am writing a script to handle some backup functionality for some of our
servers. I have been developing the script inside PowerGUI. One of the items
I need to do is to stop a service on the remote server that is being backed
up. When I run the script inside PowerGUI the service is stopped fine.
However, when I try to run my script outside of PowerGUI

(e.g. powershell -command "& 'c:\scripts\VMBackup.ps1'" > c:\vmbackup.log)

my program reports that the service couldn't be stopped. I looked at the
vmbackup.log file but it doesn't contain any reason why this would happen.

My initial thought is that there is a problem with security and the user
that is being used for the execution of my script outside of PowerGUI.

Can anyone point me in the direction to figure out why the service will stop
when running the script inside my editor but not outside my editor?

Thanks.

Marco Shaw [MVP]

unread,
Apr 22, 2008, 2:55:26 PM4/22/08
to

How exactly are you running it again? Your subject mentions "runas".
Are you trying to run it with different credentials?

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com

Snowmizer

unread,
Apr 22, 2008, 4:42:01 PM4/22/08
to
Currently I've run it inside my script editor (PowerGUI) and it runs fine. On
the same server I have also tried running it with the command I mentioned
from Start/Run. Running it from Start/Run the stop service command fails.

Thanks.

Marco Shaw [MVP]

unread,
Apr 22, 2008, 7:41:53 PM4/22/08
to

So, I'm assuming you aren't running that *exact* same command within
PowerGui?

From DOS, if you do powershell /?, you don't seem to be following the
proper syntax, which should actually be something like:

PowerShell -Command "& {Get-EventLog -LogName security}"

Snowmizer

unread,
Apr 23, 2008, 9:42:04 AM4/23/08
to
The command I'm running to stop the service is inside my script so it doesn't
change. The only thing different is the method I'm using to run my script
(executing it in my development environment vs. running the script from the
command prompt).

Thanks.

Marco Shaw [MVP]

unread,
Apr 23, 2008, 12:00:55 PM4/23/08
to

> PowerShell -Command "& {Get-EventLog -LogName security}"
>

OK, I just tried your syntax and it works fine also.

What OS? Vista? How are you starting PowerGUI? If Vista, you're
starting it elevated?

Marco

Snowmizer

unread,
Apr 23, 2008, 2:53:01 PM4/23/08
to
It's running on a Windows 2003 Std server. When I start up PowerGUI I just do
Start/Programs/PowerGUI/PowerGUI Script Editor.

Marco Shaw [MVP]

unread,
Apr 23, 2008, 3:01:58 PM4/23/08
to
Snowmizer wrote:
> It's running on a Windows 2003 Std server. When I start up PowerGUI I just do
> Start/Programs/PowerGUI/PowerGUI Script Editor.

Odd from my viewpoint.

What happens if:
1. You open a DOS window and run it (not just from Start->Run)?
2. You open a PowerShell window and run it?

Run this of course as is: "powershell -command "&

Snowmizer

unread,
Apr 25, 2008, 11:19:00 AM4/25/08
to
It seems odd from my viewpoint too. Here's the latest things I've tried:

1. Run from a command prompt the script appeared to start running but then
failed.
2. Opened Windows Powershell and ran from PS prompt. This works fine.

I've added a couple of command line arguments since we started this
conversation so now the command looks like:

powershell -command "& 'c:\scripts\VMBackup.ps1' ParmA ParmB ParmC" >
E:\VMBackup.log

Thanks.

0 new messages