Verify and Start the Citrix Profile Management Service

Verify and Start the Citrix Profile Management Service

·

2 min read

I created simple PowerShell script that checks whether the Citrix Profile Management service is running on multiple servers and starts it if it's no

$list = Get-Location
$serverListPath = "$list\citrixProfileManagementList.txt" #create one later file


$logFilePath = "$list\serviceLog.log" #will create later


$logentries = @()
$sessions = @()


$servers = Get-Content -Path $serverListPath


foreach($server in $servers){
    try {
        $session = New-PSSession -ComputerName $server -ErrorAction Stop
        $sessions += $session
    }
    catch{
        $logentry = "Server: $server - Error to create session - $_"
        $logentry += $logentry
        Write-Host $logentry
    }

}

foreach($session in $sessions){
    $serverName = $session.ComputerName
    try{
        $checkService = Invoke-Command -Session $session -ScriptBlock { Get-Service -Name "ctxprofile" -ErrorAction stop}  

        if($checkService.status -eq "running"){
            $logentry = "server $serverName  - service ctxprofile is running"
        }
        else {$logentry = "server $serverName  - service ctxprofile is not running" }

    }
    catch{
        $logentry = "Service ctxProfile not found on server: $server -error: $_"
    }

    $logEntries += $logentry
    Write-Host $logentry
}

#need to close all Pssessions
<#$sessions | ForEach-Object {
    Remove-PSSession -Session $_
} #>

#or can use like this
foreach($session in $sessions){
    Remove-PSSession -Session $session
}


$logentries | Out-File -FilePath $logFilePath -Force
$logentries | Out-GridView -Title "Service Check Results"

For checking the service is running only and outcome in Out-Grid View (OGV), can use this powershell script

$list = Get-Location
$serverListPath = "$list\citrixProfileManagementList.txt" #create one later file


$logFilePath = "$list\serviceLog.log" #will create later


$logentries = @()
$sessions = @()


$servers = Get-Content -Path $serverListPath


foreach($server in $servers){
    try {
        $session = New-PSSession -ComputerName $server -ErrorAction Stop
        $sessions += $session
    }
    catch{
        $logentry = "Server: $server - Error to create session - $_"
        $logentry += $logentry
        Write-Host $logentry
    }

}

foreach($session in $sessions){
    $serverName = $session.ComputerName
    try{
        $checkService = Invoke-Command -Session $session -ScriptBlock { Get-Service -Name "ctxprofile" -ErrorAction stop}  

        if($checkService.status -eq "running"){
            $logentry = "server $serverName  - service ctxprofile is running"
        }
        else {$logentry = "server $serverName  - service ctxprofile is not running" }

    }
    catch{
        $logentry = "Service ctxProfile not found on server: $server -error: $_"
    }

    $logEntries += $logentry
    Write-Host $logentry
}

#need to close all Pssessions
<#$sessions | ForEach-Object {
    Remove-PSSession -Session $_
} #>

#or can use like this
foreach($session in $sessions){
    Remove-PSSession -Session $session
}


$logentries | Out-File -FilePath $logFilePath -Force
$logentries | Out-GridView -Title "Service Check Results"