• Citrix Provisioning Services Assessment Script Update Version 1.12

    February 28, 2017

    PowerShell, PVS

    While helping a customer for my employer, Choice Solutions, with a PVS issue, we noticed their PVS service had no failure actions set. I figured that would be a good item to add to the PVS Assessment script.

    #Version 1.12 28-Feb-2017

    • Added Citrix PVS Services Failure Actions Appendix F2
    Figure 1
    Figure 1

    This was way more involved that I thought it would be. In the end, there wasn’t much code involved, it just took me a good while to figure out how to process output from the sc.exe utility.

    Function GetPVSServiceInfo
    {
    	Param([string]$ComputerName)
    
    	Write-Host -foregroundcolor Yellow -backgroundcolor Black "VERBOSE: $(Get-Date): Processing PVS Services for Server $($server.servername)"
    	$Services = Get-WmiObject -ComputerName $ComputerName Win32_Service -EA 0 | `
    	Where-Object {$_.DisplayName -like "Citrix PVS*"} | `
    	Select displayname, name, status, startmode, started, startname, state 
    	
    	If($? -and $Null -ne $Services)
    	{
    		ForEach($Service in $Services)
    		{
    			$obj1 = New-Object -TypeName PSObject
    			
    			$obj1 | Add-Member -MemberType NoteProperty -Name ServerName 	-Value $ComputerName
    			$obj1 | Add-Member -MemberType NoteProperty -Name DisplayName	-Value $Service.DisplayName
    			$obj1 | Add-Member -MemberType NoteProperty -Name Name  	-Value $Service.Name
    			$obj1 | Add-Member -MemberType NoteProperty -Name Status	-Value $Service.Status
    			$obj1 | Add-Member -MemberType NoteProperty -Name StartMode  	-Value $Service.StartMode
    			$obj1 | Add-Member -MemberType NoteProperty -Name Started	-Value $Service.Started
    			$obj1 | Add-Member -MemberType NoteProperty -Name StartName  	-Value $Service.StartName
    			$obj1 | Add-Member -MemberType NoteProperty -Name State  	-Value $Service.State
    			
    			#start of add failure actions
    			[array]$Actions = sc.exe \\$ComputerName qfailure $Service.Name
    			
    			If($Actions.Length -gt 0)
    			{
    				If(($Actions -like "*RESTART -- Delay*") -or ($Actions -like "*RUN PROCESS -- Delay*") -or ($Actions -like "*REBOOT -- Delay*"))
    				{
    					$cnt = 0
    					ForEach($Item in $Actions)
    					{
    						Switch ($Item)
    						{
    							{$Item -like "*RESTART -- Delay*"}	{$cnt++; $obj1 | Add-Member -MemberType NoteProperty -Name $("FailureAction$($Cnt)") -Value "Restart the Service"}
    							{$Item -like "*RUN PROCESS -- Delay*"}	{$cnt++; $obj1 | Add-Member -MemberType NoteProperty -Name $("FailureAction$($Cnt)") -Value "Run a Program"}
    							{$Item -like "*REBOOT -- Delay*"}	{$cnt++; $obj1 | Add-Member -MemberType NoteProperty -Name $("FailureAction$($Cnt)") -Value "Restart the Computer"}
    						}
    					}
    				}
    				Else
    				{
    					$obj1 | Add-Member -MemberType NoteProperty -Name FailureAction1 -Value "Take no Action"
    					$obj1 | Add-Member -MemberType NoteProperty -Name FailureAction2 -Value "Take no Action"
    					$obj1 | Add-Member -MemberType NoteProperty -Name FailureAction3 -Value "Take no Action"
    				}
    			}
    			#end failure actions
    			
    			$Script:PVSServiceItems +=  $obj1
    		}
    	}
    	Else
    	{
    		Line 2 "No PVS services found for $($ComputerName)"
    	}
    	Line 0 ""
    }
    

    You can always find the most current script by going to https://carlwebster.com/where-to-get-copies-of-the-documentation-scripts/

    Thanks

    Webster

    About Carl Webster

    Webster is a Sr. Solutions Architect for Choice Solutions, LLC and specializes in Citrix, Active Directory and Technical Documentation. Webster has been working with Citrix products for many years starting with Multi-User OS/2 in 1990.

    View all posts by Carl Webster

    No comments yet.

    Leave a Reply