Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#region create global conditions if they don't exist and find OS GC
#region GC Office Product function
function Get-CMOfficeGlobalCondition {
[CmdletBinding()]
param (
[parameter(Mandatory = $true)]
[validateset('Project Professional', 'Project Standard', 'Project', 'Visio Professional', 'Visio Standard', 'Visio')]
[string]$Application
)
$GC_Name = [string]::Format('Condition Detection - Microsoft {0}', $Application)
switch ($Application) {
'Project Professional' {
$MSI_App = 'PRJPRO'
$C2R_App = 'PROJECTPRO'
}
'Project Standard' {
$MSI_App = 'PRJSTD'
$C2R_App = 'PROJECTSTD'
}
'Project' {
if (-not ($GC = Get-CMGlobalCondition -Name $GC_Name)) {
Write-Warning "Global condition not found: Creating GC '$GC_Name'"
$ruleProjPro = Get-CMOfficeGlobalCondition -Application 'Project Professional' | New-CMRequirementRuleBooleanValue -Value $true
$ruleProjStd = Get-CMOfficeGlobalCondition -Application 'Project Standard' | New-CMRequirementRuleBooleanValue -Value $true
$expressionProject = New-CMRequirementRuleExpression -AddRequirementRule $ruleProjPro, $ruleProjStd -ClauseOperator Or
$GC = New-CMGlobalConditionExpression -Name $GC_Name -DeviceType Windows -RootExpression $expressionProject
}
else {
Write-Verbose "Using existing Global Condition with name $($GC.LocalizedDisplayName)"
}
return $GC
}
'Visio Professional' {
$MSI_App = 'VISPRO'
$C2R_App = 'VISIOPRO'
}
'Visio Standard' {
$MSI_App = 'VISSTD'
$C2R_App = 'VISIOSTD'
}
'Visio' {
if (-not ($GC = Get-CMGlobalCondition -Name $GC_Name)) {
Write-Warning "Global condition not found: Creating GC '$GC_Name'"
$ruleVisPro = Get-CMOfficeGlobalCondition -Application 'Visio Professional' | New-CMRequirementRuleBooleanValue -Value $true
$ruleVisStd = Get-CMOfficeGlobalCondition -Application 'Visio Standard' | New-CMRequirementRuleBooleanValue -Value $true
$expressionVisio = New-CMRequirementRuleExpression -AddRequirementRule $ruleVisPro, $ruleVisStd -ClauseOperator Or
$GC = New-CMGlobalConditionExpression -Name $GC_Name -DeviceType Windows -RootExpression $expressionVisio
}
else {
Write-Verbose "Using existing Global Condition with name $($GC.LocalizedDisplayName)"
}
return $GC
}
}
$GC_Script = @"
`$MSI_App = '$MSI_App'
`$C2R_App = '$C2R_App'
`$RegMSIx86Uninstall = Get-ChildItem -Path 'REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'
`$RegMSIx64Uninstall = Get-ChildItem -Path 'REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\'
`$RegC2R = Get-ItemProperty -Path REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration
`$MSIx86 = `$RegMSIx86Uninstall | Where-Object { `$_.PSChildName -match "^OFFICE[0-9]{2}\.`$MSI_App`$" }
`$MSIx64 = `$RegMSIx64Uninstall | Where-Object { `$_.PSChildName -match "^OFFICE[0-9]{2}\.`$MSI_App`$" }
`$C2R = `$RegC2R | Where-Object { `$_.ProductReleaseIDs -match `$C2R_App -and `$_.Platform -eq '$Bitness' }
if (`$MSIx86 -or `$MSIx64 -or `$C2R) {
`$true
}
else {
`$false
}
"@
if (-not ($GC = Get-CMGlobalCondition -Name $GC_Name)) {
Write-Warning "Global condition not found: Creating GC '$GC_Name'"
$GC = New-CMGlobalConditionScript -DataType Boolean -ScriptText $GC_Script -ScriptLanguage PowerShell -Name $GC_Name
}
else {
Write-Verbose "Using existing Global Condition with name $($GC.LocalizedDisplayName)"
}
return $GC
}
#endregion GC Office Product function
Set-Location -Path $SiteCodePath
Write-Output $('-' * 50)
Write-Output "Identifying and creating global conditions as needed for detection of Visio/Project Pro/Standard"
$VisStandard_GC = Get-CMOfficeGlobalCondition -Application 'Visio Standard'
$VisPro_GC = Get-CMOfficeGlobalCondition -Application 'Visio Professional'
$Vis_GC = Get-CMOfficeGlobalCondition -Application Visio
$ProjPro_GC = Get-CMOfficeGlobalCondition -Application 'Project Professional'
$ProjStandard_GC = Get-CMOfficeGlobalCondition -Application 'Project Standard'
$Proj_GC = Get-CMOfficeGlobalCondition -Application Project
$OS_GC = Get-CMGlobalCondition -Name 'Operating System' | Where-Object { $_.ModelName -eq 'GLOBAL/OperatingSystem' }
Write-Output "All global conditions identified or created"
#endregion create global conditions if they don't exist and find OS GC
#region create our requirements for use in the DeploymentTypes
Write-Output $('-' * 50)
Write-Output "Creating CMRequirementRules that can be applied to deployment types based on our global conditions"
$2016_Rule = $OS_GC | New-CMRequirementRuleOperatingSystemValue -PlatformString Windows/All_x64_Windows_7_Client, Windows/All_x64_Windows_8_Client, Windows/All_x64_Windows_8.1_Client -RuleOperator OneOf
$2019_Rule = $OS_GC | New-CMRequirementRuleOperatingSystemValue -PlatformString Windows/All_x64_Windows_10_and_higher_Clients -RuleOperator OneOf
$VisStandard_Rule = $VisStandard_GC | New-CMRequirementRuleBooleanValue -Value $true
$VisPro_Rule = $VisPro_GC | New-CMRequirementRuleBooleanValue -Value $true
$Vis_Rule = $Vis_GC | New-CMRequirementRuleBooleanValue -Value $true
$ProjStandard_Rule = $ProjStandard_GC | New-CMRequirementRuleBooleanValue -Value $true
$ProjPro_Rule = $ProjPro_GC | New-CMRequirementRuleBooleanValue -Value $true
$Proj_Rule = $Proj_GC | New-CMRequirementRuleBooleanValue -Value $true
Write-Output "CMRequirementRules created"
#endregion create our requirements for use in the DeploymentTypes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment