Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Virtualization » Virtualization and PowerShell

Thread: Run Powershell script as Windows Task possible?


Permlink Replies: 1 - Pages: 1 - Last Post: Jan 27, 2009 12:31 PM by: Shay Levy
deercutter

Posts: 1
Registered: 1/27/09
Run Powershell script as Windows Task possible?
Posted: Jan 27, 2009 10:40 AM
  Click to reply to this thread Reply

Hello to all! I am a Powershell newbie, and I am having a bit of trouble running a script called healthcheck.ps1.  The script runs fine if I run it via PowerGui or Windows Powershell, but when I try to run it via a WindowsXP SP2 workstation 'Start>Run', it bombs. Here is the output from the 'Run' command:

powershell.exe -noprofile -command "& 'C:\Healthcheck.ps1' "

The error message I receive is as follows:
C:\>powershell.exe -noprofile -noexit -Noninteractive -command "& 'C:\Healthchec
k.ps1' "
The term 'connect-VIServer' is not recognized as a cmdlet, function, operable p
rogram, or script file. Verify the term and try again.
At C:\Healthcheck.ps1:61 char:17
+ connect-VIServer  <<<< $vcserver
The term 'get-view' is not recognized as a cmdlet, function, operable program,
or script file. Verify the term and try again.
At C:\Healthcheck.ps1:67 char:22
+ $vcversion = get-view  <<<< serviceinstance

...and on, and on, an on

What am I missing?

Thanks!




Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Run Powershell script as Windows Task possible?
Posted: Jan 27, 2009 12:31 PM   in response to: deercutter
  Click to reply to this thread Reply

Make sure you load the VI snapin in the script, put it on the first line:


Add-PSSnapIn VMware.VimAutomation.Core

...
rest of the script
...

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums