VMware Cloud Community
Zapatone
Enthusiast
Enthusiast
Jump to solution

script to call other script when no tasks running in vCenter

Hi All!

I try to make a script when it detects that in vcenter Server there is no task running, call another scrip and run it, and if not meanwhile wait for the tasks to finish running and so once the tasks are running, run the other script..

any idea?

thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This will wait until the running tasks on your vCenter are completed, and then start a script.

while(Get-Task -Status Running -Server $global:DefaultVIServer){

    sleep 10

}

.\other-script.ps1


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

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

What exactly do you mean with "there is no task running"?

I hope you are not running PowerCLI scripts on your vCenter?


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

Reply
0 Kudos
Zapatone
Enthusiast
Enthusiast
Jump to solution

for example to no task of machine migration or similar in execution in the vCenter

No, no, im not running PowerCLI scripts on my vCenter

thanks

Reply
0 Kudos
IT_pilot
Expert
Expert
Jump to solution

Do {Wait-Event -Timeout 10; Write-Host State: Running} While ((Get-Task).State -eq 'Running'); Script.ps1

every ten seconds we check whether there are any running tasks with simultaneous printing of "State: Running". As the absence of tasks is detected, the script is launched.

http://it-pilot.ru
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

This will wait until the running tasks on your vCenter are completed, and then start a script.

while(Get-Task -Status Running -Server $global:DefaultVIServer){

    sleep 10

}

.\other-script.ps1


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

Reply
0 Kudos
Zapatone
Enthusiast
Enthusiast
Jump to solution

finally i solve this with next code:

while(Get-Task -Status Running -Server $global:DefaultVIServer){

    sleep 10

}

# Obtener la ruta del script:

$ScriptRoute = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "Modo_mantenimiento_sprint_test.ps1"))

# Ejecutar el script en su ruta:

&"$ScriptRoute"

Thanks to all!

Regards


					
				
			
			
				
			
			
			
			
			
			
			
		
Reply
0 Kudos