Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify provisioning type reliably #13

Closed
megamorf opened this issue Jul 17, 2017 · 0 comments
Closed

Identify provisioning type reliably #13

megamorf opened this issue Jul 17, 2017 · 0 comments

Comments

@megamorf
Copy link
Owner

megamorf commented Jul 17, 2017

I have come up with different approaches to identify whether a machine is provisioned via PVS, MCS or manually.

Version 1 - hacky

function Get-ProvisioningType
{
    <#
    .SYNOPSIS
        Returns the provisioning type of a system.

    .DESCRIPTION
        Returns an error if no FMA service is found on the system.
        Otherwise returns one of the following:

        PVS    - if PVS Device Service is found
        MCS    - if Linked Clone disk is found
        Manual - fallback

    .EXAMPLE
        Get-ProvisioningType

        PVS

    .NOTES
        ToDo: add tags, author info
    #>

    [OutputType([string])]
    [CmdletBinding()]
    param()

    # Check XA/XD agent installation
    [bool]$CitrixAgentInstalled = Get-Service -Name "BrokerAgent" -ErrorAction SilentlyContinue
    if (-not $CitrixAgentInstalled)
    {
        throw "No Citrix VDA (MFA) agent found on the system!"
    }


    if (Get-Service -Name 'BNDevice' -ErrorAction SilentlyContinue)
    {
        Write-Verbose -Message ('Citrix PVS Device Service found -> PVS' | AddPrefix)
        return 'PVS'
    }

    if (Get-Partition | Where-Object AccessPaths -contains "C:\Program Files\Citrix\PvsVm\Service\PersistedData\")
    {
        Write-Verbose -Message ('Linked Clone Disk found -> MCS' | AddPrefix)
        return 'MCS'
    }

    Write-Verbose -Message ('PVS/MCS identification failed -> Manual' | AddPrefix)
    return 'Manual'
}

Version 2 - assumes there's no PVS Device service on non-PVS machines

function Get-ProvisioningType
{
    <#
    .SYNOPSIS
        Returns the provisioning type of a system.

    .DESCRIPTION
        Returns an error if no FMA service is found on the system.
        Otherwise returns one of the following:

        PVS    - if PVS Service and personality file contains a WriteCacheType setting
        MCS    - if no PVS Service and personality file has a shared disk mode
        Manual - if no PVS Service and personality file has a private disk mode

    .EXAMPLE
        Get-ProvisioningType

        PVS

    .NOTES
        ToDo: add tags, author info
    #>

    [OutputType([string])]
    [CmdletBinding()]
    param()

    # Check XA/XD agent installation
    [bool]$CitrixAgentInstalled = Get-Service -Name "BrokerAgent" -ErrorAction SilentlyContinue
    if (-not $CitrixAgentInstalled)
    {
        throw "No Citrix VDA (MFA) agent found on the system!"
    }

    $Personality = Import-IniFile -FilePath "$env:systemdrive\personality.ini"
    $PvsServiceFound  = [bool](Get-Service -Name 'BNDevice' -ErrorAction SilentlyContinue)

    if ($PvsServiceFound -and $Personality.StringData.ContainsKey('$WriteCacheType'))
    {
        Write-Verbose -Message ('PVS Service and WriteCache setting found -> PVS' | AddPrefix)
        return 'PVS'
    }
    elseif (-not $PvsServiceFound -and $Personality.StringData.'$DiskMode' -eq 'Shared')
    {
        Write-Verbose -Message ('No PVS Service but Shared disk mode found -> MCS' | AddPrefix)
        return 'MCS'
    }
    elseif(-not $PvsServiceFound -and $Personality.StringData.'$DiskMode' -eq 'Private')
    {
        Write-Verbose -Message ('No PVS Service but Private disk mode found -> Manual' | AddPrefix)
        return 'Manual'
    }

    Write-Verbose -Message ('PVS/MCS identification failed. Aborting...' | AddPrefix)
    throw "Could not reliably identify provisioning type"
}

@jariangibson can you verify both options in your environment? (you'll have to import the module beforehand or add the Import-IniFile and AddPrefix functions prior to running them)

@megamorf megamorf closed this as completed Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant