Hello all, I am having difficulty getting a script to run as a scheduled task. When I run it from the vSphere PowerCLI it works a treat.
When I run it via command line using the command to run as a scheduled task it finishes very quickly and I get the mail stating The Connect-VIServer Cmdlet did not work, please check you VI Server.
I know this error is just a return Alan has built into his script but struggling to get past this bit. I am sure I am doing something stoopid as I know the script works very well for others.
I am debugging using the VESI editor and am having difficulty finding where I am going wrong.
I get the following error
Cannot validate argument on parameter 'server'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
The actual line is
$VIServer = Connect-VIServer $VISRV
Further up the script I have the line
if ($VISRV -eq "")
blah blah blah which returns an error if the VC name is not within the quotations.
I have put the name of the VC inside the quotes which I have assumed (maybe wrongly) that this is the argument for $VISRV. When I put the VC name in this location and debug the script it gets past this bit and gets to the issue I am having.
Any help most appreciated.
H
Kevin,
you have to pass the name of your vCenter server as a parameter to the vCheck script. For example:
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -command "&{c:\vCheck.ps1 vCenterServerName}"
Remember to run the scheduled task with an account that has sufficient privileges on your VMware environment.
Regards, Robert
Kevin,
you have to pass the name of your vCenter server as a parameter to the vCheck script. For example:
%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -command "&{c:\vCheck.ps1 vCenterServerName}"
Remember to run the scheduled task with an account that has sufficient privileges on your VMware environment.
Regards, Robert
Thank you Robert, I took out pointing to the VC name within the script and used your command and sorted much appreciated.
H