VMware Cloud Community
wilber822
Enthusiast
Enthusiast
Jump to solution

Script pending on Running status when schedule as task

Hello everyone,

I face this problem on every script, it's hard for me to find root cause, can some one help please? 🙂

My script usually contains following line to load PowerCLI:

add-pssnapin VMware.VimAutomation.Core

Whenever I run it on PowerShell prompt window, it's working fine.

I created scheduled task to run the script daily, first several runs worked fine, but it's pending on load PowerCLI snapin after few days, no error, just pending there.

I tried create task by .ps1 file directly and by .bat, no help.

I tried on PowerShell 2.0 with PowerCLI 5.5 Release 1, and PowerShell 3.0 with PowerCLI 5.5 Release 2, both does not work.

It's not mentioned on PowerCLI release notes.

20140628074609.png

*****************************************************

My server is Windows Server 2008 R2.

Following is PowerShell version:

Name                           Value

----                           -----

WSManStackVersion              3.0

PSCompatibleVersions           {1.0, 2.0, 3.0}

SerializationVersion           1.1.0.1

BuildVersion                   6.2.9200.16398

PSVersion                      3.0

CLRVersion                     4.0.30319.1022

PSRemotingProtocolVersion      2.2

Following is PowerCLI version:

PowerCLI Version

----------------

   VMware vSphere PowerCLI 5.5 Release 2 build 1671586

---------------

Snapin Versions

---------------

   VMWare AutoDeploy PowerCLI Component 5.5 build 1598391

   VMWare ImageBuilder PowerCLI Component 5.5 build 1598391

   VMware License PowerCLI Component 5.5 build 1265954

   VMware VDS PowerCLI Component 5.5 build 1671576

   VMware vSphere PowerCLI Component 5.5 build 1671576

https://www.zhengwu.org
1 Solution

Accepted Solutions
wilber822
Enthusiast
Enthusiast
Jump to solution

Thanks for your helping LucD, I figured out it.

Please refer my blog for solution!

Extremely slow when run PowerShell script by scheduled taks

https://www.zhengwu.org

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

Sometimes this is caused by warning messages.

Can you try to disable warning messages ?

You can add the line

$WarningPreference = "SilentlyContinue"

to the script.

Or if it's PowerCLI warnings you can do

Set-PowerCliConfiguration - DisplayDeprecationWarnings:$false


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wilber822
Enthusiast
Enthusiast
Jump to solution

I'm using this line, is that same like your first line?

$ErrorActionPreference = "SilentlyContinue"

Regarding the second line, I guess it's functional after full load VMware.VimAutomation.Core, but my problem is the script looks like pending on load the snapin...

https://www.zhengwu.org
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, that line is to suppress the prompt after an error occurs, the one I mentioned is to suppress an action prompt after a Warning.

Yes, the 2nd one is only valid after you load the PowerCLI pssnapin.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
wilber822
Enthusiast
Enthusiast
Jump to solution

Thanks for your helping LucD, I figured out it.

Please refer my blog for solution!

Extremely slow when run PowerShell script by scheduled taks

https://www.zhengwu.org
LucD
Leadership
Leadership
Jump to solution

Nice find, thanks for sharing


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos