VMware Cloud Community
xSyteck
Enthusiast
Enthusiast

Jobs hanging when scriptblock needs to print output

Hello there,

I've found many thread and forum that were subject to this bug (?), but I didn't find a solution that suits my environnement...

I'm working on a Linux CentOS 7 with a PowerShell 6.1.1 package on it. I'm trying to make a loading print that show PowerCli commands is still running and is not crashed 'cause sometimes it's... Very... Very long...

The issue is when I run the loading script the jobs never ends, the only one way to make them finish properly is to redirect output, if there are output directed to the console it hangs.

However I want to keep the object that are returned from my jobs commands, I tried to Export-Clixml those outputs but the issue happens in this situation and I didn't find a way to export my objects in a xml file and avoid the issue by redirecting the output, if I do both export and redirect the xml file is empty.

I've tried with simple commands passed to the -ScriptBlockString parameter, like Get-VM.

This script is adapted from this one: http://www.vxav.fr/2017-08-08-easily-run-powercli-commands-as-jobs/

Thanks !

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

It's not clear to me which bug you are referring to?

When I run your script in PS v6 on a Windows box, everything seems to work ok.

Did you encounter the same issue on other systems besides CentOS 7?


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

Reply
0 Kudos
xSyteck
Enthusiast
Enthusiast

I can't use anything else than CentOS, it's a gateway builded to have specific access to our vCenter.

There is some link I've found about this bug:

https://communities.vmware.com/thread/461742

This one were resolved by the post 5 and 7, the 5th is useable for me because of my environnement (CentOS), the 7th works and is similar to the next link: redirect output to a variable/file/nothing

https://stackoverflow.com/questions/46524293/powercli-powershell-jobs-does-not-finish

So the workaround is to use redirection to avoid jobs to hang. It works for me, but I want to use my object afterwards, so I tried to use Export-Clixml but either the jobs keeps hanging or the xml file is empty...

Reply
0 Kudos
LucD
Leadership
Leadership

To make sure, did set the DisplayDepreciationWarnings option to $false with the Set-PowerCLIConfiguration cmdlet?

You might try adding that as the 1st line in the script you launch with Start-Job.


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

Reply
0 Kudos
xSyteck
Enthusiast
Enthusiast

It doesn't work even with the set command at the start of the job script block.

Can't paste the Get-PowerCLIConfiguration command but the DisplayDeprecationWarnings are on false for all users.

Reply
0 Kudos
LucD
Leadership
Leadership

You have to make sure the settings is false for the Session.
If that still is true, the AllUsers will be overruled.


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

Reply
0 Kudos
xSyteck
Enthusiast
Enthusiast

Hello, sorry for the delay, I've set this parameter to false for the session at the start of the job without more success.. 
Reply
0 Kudos