reset to imadbk version
This commit is contained in:
parent
acc2973fd9
commit
0499544f5c
1 changed files with 194 additions and 194 deletions
|
|
@ -136,7 +136,7 @@ param(
|
|||
[string]$Config
|
||||
)
|
||||
|
||||
#region ######## FUNCTIONS #########
|
||||
######### FUNCTIONS #########
|
||||
|
||||
# Create Write-Log function
|
||||
function Write-Log() {
|
||||
|
|
@ -438,10 +438,10 @@ function Get-DynamicDeadline() {
|
|||
$UpdateID = Get-CMUpdate
|
||||
}
|
||||
# Getting application information from WMI
|
||||
elseif ($RunApplicationIDValue) {
|
||||
elseif ($RunApplicationIDEnabled -eq "True") {
|
||||
Write-Log -Message "RunApplicationIDEnabled is True. Trying to get deadline information based on application id"
|
||||
try {
|
||||
$ApplicationID = Get-CimInstance -Namespace root\ccm\clientsdk -Query "SELECT * FROM CCM_Application where ID = '$RunApplicationIDValue'"
|
||||
$ApplicationID = Get-CimInstance -Namespace root\ccm\clientsdk -Query "SELECT * FROM CCM_Application where ID = '$DynDeadlineValue'"
|
||||
}
|
||||
catch {
|
||||
Write-Log -Level Error -Message "Failed to get Application ID from WMI"
|
||||
|
|
@ -614,8 +614,21 @@ function Write-PackageIDRegistry() {
|
|||
}
|
||||
}
|
||||
|
||||
# Create Test-ApplicationID function for checking, that App with given ID is deployed to the client
|
||||
function Test-ApplicationID() {
|
||||
# Create Write-ApplicationIDRegistry function
|
||||
function Write-ApplicationIDRegistry() {
|
||||
Write-Log -Message "Running Write-ApplicationIDRegistry function"
|
||||
$RegistryPath = "HKCU:\SOFTWARE\ToastNotificationScript"
|
||||
$RegistryName = "RunApplicationID"
|
||||
# Making sure that the registry path being used exists
|
||||
if (-NOT(Test-Path -Path $RegistryPath)) {
|
||||
try {
|
||||
New-Item -Path $RegistryPath -Force
|
||||
}
|
||||
catch {
|
||||
Write-Log -Level Error -Message "Error. Could not create ToastNotificationScript registry path"
|
||||
}
|
||||
}
|
||||
# If the ApplicationID specified in the config.xml is picked up
|
||||
if ($RunApplicationIDValue) {
|
||||
# If the ConfigMgr service exist
|
||||
if (Get-Service -Name ccmexec -ErrorAction SilentlyContinue) {
|
||||
|
|
@ -630,6 +643,15 @@ function Test-ApplicationID() {
|
|||
# If the ApplicationID is found in WMI with the ConfigMgr client, tattoo that ApplicationID into registry
|
||||
if ($TestApplicationID) {
|
||||
Write-Log -Message "ApplicationID: $RunApplicationIDValue was found in WMI as deployed to the client"
|
||||
Write-Log -Message "Writing the ApplicationID to registry"
|
||||
if ((Get-ItemProperty -Path $RegistryPath -Name $RegistryName -ErrorAction SilentlyContinue).$RegistryName -ne $RunApplicationIDValue) {
|
||||
try {
|
||||
New-ItemProperty -Path $RegistryPath -Name $RegistryName -Value $RunApplicationIDValue -PropertyType "String" -Force
|
||||
}
|
||||
catch {
|
||||
Write-Log -Level Error -Message "Failed to write ApplicationID: $RunApplicationIDValue to registry"
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Log -Level Error -Message "ApplicationID: $RunApplicationIDValue was not found in WMI as deployed to the client. Please check the config.xml or deployment in ConfigMgr"
|
||||
|
|
@ -766,7 +788,7 @@ function Write-CustomActionRegistry() {
|
|||
New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
$RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd %1"
|
||||
$RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd"
|
||||
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
}
|
||||
catch {
|
||||
|
|
@ -811,7 +833,7 @@ function Write-CustomActionRegistry() {
|
|||
New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
$RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd %1"
|
||||
$RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd"
|
||||
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
}
|
||||
catch {
|
||||
|
|
@ -1028,7 +1050,7 @@ exit 0
|
|||
}
|
||||
try {
|
||||
$GetCustomScriptPath = $PathInfo.FullName
|
||||
[String]$Script = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File `"$global:CustomScriptsPath\ToastRunApplicationID.ps1`" %1"
|
||||
[String]$Script = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File `"$global:CustomScriptsPath\ToastRunApplicationID.ps1`""
|
||||
if (-NOT[string]::IsNullOrEmpty($Script)) {
|
||||
Out-File -FilePath $GetCustomScriptPath -InputObject $Script -Encoding ASCII -Force
|
||||
}
|
||||
|
|
@ -1058,25 +1080,19 @@ exit 0
|
|||
try {
|
||||
$GetCustomScriptPath = $PathInfo.FullName
|
||||
[String]$Script = @'
|
||||
$ApplicationID = $args[0]
|
||||
if (!$ApplicationID) { throw "ApplicationID wasn't specified" }
|
||||
$ApplicationID = ($ApplicationID -replace '^[^:]*:').trim()
|
||||
if ($ApplicationID -notmatch "^ScopeId_.+/Application_.+") { throw "ApplicationID ($ApplicationID) isn't in correct format (regex `"^ScopeId_.+/Application_.+`"" }
|
||||
|
||||
$TestApplicationID = Get-CimInstance -ClassName CCM_Application -Namespace ROOT\ccm\ClientSDK | Where-Object { $_.Id -eq $ApplicationID }
|
||||
|
||||
$RegistryPath = "HKCU:\SOFTWARE\ToastNotificationScript"
|
||||
$ApplicationID = (Get-ItemProperty -Path $RegistryPath -Name "RunApplicationID").RunApplicationID
|
||||
$TestApplicationID = Get-CimInstance -ClassName CCM_Application -Namespace ROOT\ccm\ClientSDK | Where-Object {$_.Id -eq $ApplicationID}
|
||||
$AppArguments = @{
|
||||
Id = $TestApplicationID.Id
|
||||
IsMachineTarget = $TestApplicationID.IsMachineTarget
|
||||
Revision = $TestApplicationID.Revision
|
||||
}
|
||||
|
||||
if (-NOT[string]::IsNullOrEmpty($TestApplicationID)) {
|
||||
if ($TestApplicationID.InstallState -eq "NotInstalled") { Invoke-CimMethod -Namespace "ROOT\ccm\clientSDK" -ClassName CCM_Application -MethodName Install -Arguments $AppArguments }
|
||||
elseif ($TestApplicationID.InstallState -eq "Installed") { Invoke-CimMethod -Namespace "ROOT\ccm\clientSDK" -ClassName CCM_Application -MethodName Repair -Arguments $AppArguments }
|
||||
if (Test-Path -Path "$env:windir\CCM\ClientUX\SCClient.exe") { Start-Process -FilePath "$env:windir\CCM\ClientUX\SCClient.exe" -ArgumentList "SoftwareCenter:Page=InstallationStatus" -WindowStyle Maximized }
|
||||
}
|
||||
|
||||
exit 0
|
||||
'@
|
||||
if (-NOT[string]::IsNullOrEmpty($Script)) {
|
||||
|
|
@ -1100,9 +1116,7 @@ exit 0
|
|||
}
|
||||
}
|
||||
|
||||
#endregion ######## FUNCTIONS #########
|
||||
|
||||
#region ######## GENERAL VARIABLES #########
|
||||
######### GENERAL VARIABLES #########
|
||||
# Global variables
|
||||
# Setting global script version
|
||||
$global:ScriptVersion = "2.1.0"
|
||||
|
|
@ -1260,6 +1274,8 @@ if(-NOT[string]::IsNullOrEmpty($Xml)) {
|
|||
$CreateScriptsProtocolsEnabled = $Xml.Configuration.Option | Where-Object {$_.Name -like 'CreateScriptsAndProtocols'} | Select-Object -ExpandProperty 'Enabled'
|
||||
$RunPackageIDEnabled = $Xml.Configuration.Option | Where-Object {$_.Name -like 'RunPackageID'} | Select-Object -ExpandProperty 'Enabled'
|
||||
$RunPackageIDValue = $Xml.Configuration.Option | Where-Object {$_.Name -like 'RunPackageID'} | Select-Object -ExpandProperty 'Value'
|
||||
$RunApplicationIDEnabled = $Xml.Configuration.Option | Where-Object {$_.Name -like 'RunApplicationID'} | Select-Object -ExpandProperty 'Enabled'
|
||||
$RunApplicationIDValue = $Xml.Configuration.Option | Where-Object {$_.Name -like 'RunApplicationID'} | Select-Object -ExpandProperty 'Value'
|
||||
# ConfigMgr Software Updates
|
||||
# Added in version 2.0.0
|
||||
$RunUpdateIDEnabled = $Xml.Configuration.Option | Where-Object {$_.Name -like 'RunUpdateID'} | Select-Object -ExpandProperty 'Enabled'
|
||||
|
|
@ -1343,38 +1359,6 @@ if(-NOT[string]::IsNullOrEmpty($Xml)) {
|
|||
}
|
||||
}
|
||||
|
||||
#endregion ####### GENERAL VARIABLES #########
|
||||
|
||||
#region ####### CHECKS #########
|
||||
|
||||
if ($ActionButton1Content -match "^ToastRunApplicationID:\s*$") {
|
||||
Write-Log -Level Error -Message "Error. Incomplete Value in the $Config file Action1 tag"
|
||||
Write-Log -Level Error -Message "Error. You have to specify also the Application share link in format: ToastRunApplicationID:ScopeId_XXX/Application_YYY"
|
||||
Write-Log -Level Error -Message "Error. Application Share link can be found in Software Center by clicking on share icon on top right of the screen"
|
||||
Exit 1
|
||||
}
|
||||
if ($ActionButton2Content -match "^ToastRunApplicationID:\s*$") {
|
||||
Write-Log -Level Error -Message "Error. Incomplete Value in the $Config file Action2 tag"
|
||||
Write-Log -Level Error -Message "Error. You have to specify also the Application share link in format: ToastRunApplicationID:ScopeId_XXX/Application_YYY"
|
||||
Write-Log -Level Error -Message "Error. Application Share link can be found in Software Center by clicking on share icon on top right of the screen"
|
||||
Exit 1
|
||||
}
|
||||
# Check if given Application ID is valid
|
||||
if ($ActionButton1Content -match "^ToastRunApplicationID:ScopeId_.+/Application_.+") {
|
||||
$RunApplicationIDValue = ($ActionButton1Content -replace '^[^:]*:').trim()
|
||||
Test-ApplicationID
|
||||
}
|
||||
if ($ActionButton2Content -match "^ToastRunApplicationID:ScopeId_.+/Application_.+") {
|
||||
$RunApplicationIDValue = ($ActionButton2Content -replace '^[^:]*:').trim()
|
||||
Test-ApplicationID
|
||||
}
|
||||
# because of dynamic deadline retrieval I allow just one installation
|
||||
if ($ActionButton2Content -match "^ToastRunApplicationID:" -and $RunApplicationIDValue) {
|
||||
Write-Log -Level Error -Message "Error. Multiple Application installations defined in the $Config file through the Action tags"
|
||||
Write-Log -Level Error -Message "Error. Only one application can be installed, so modify one of Action options"
|
||||
Exit 1
|
||||
}
|
||||
|
||||
# Check if toast is enabled in config.xml
|
||||
if ($ToastEnabled -ne "True") {
|
||||
Write-Log -Message "Toast notification is not enabled. Please check $Config file"
|
||||
|
|
@ -1472,6 +1456,18 @@ if (($DeadlineEnabled -eq "True") -AND ($DynDeadlineEnabled -eq "True")) {
|
|||
Write-Log -Level Error -Message "You should only enable one of the deadline options. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
if (($RunApplicationIDEnabled -eq "True") -AND ($RunPackageIDEnabled -eq "True")) {
|
||||
Write-Log -Level Error -Message "Error. Conflicting selection in the $Config file"
|
||||
Write-Log -Level Error -Message "Error. You can't have RunApplicationIDEnabled set to True and RunPackageIDEnabled set to True at the same time"
|
||||
Write-Log -Level Error -Message "You should only enable one of the options. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
if (($RunApplicationIDEnabled -eq "True") -AND ($RunUpdateIDEnabled -eq "True")) {
|
||||
Write-Log -Level Error -Message "Error. Conflicting selection in the $Config file"
|
||||
Write-Log -Level Error -Message "Error. You can't have RunApplicationIDEnabled set to True and RunUpdateIDEnabled set to True at the same time"
|
||||
Write-Log -Level Error -Message "You should only enable one of the options. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
if (($RunUpdateIDEnabled -eq "True") -AND ($RunPackageIDEnabled -eq "True")) {
|
||||
Write-Log -Level Error -Message "Error. Conflicting selection in the $Config file"
|
||||
Write-Log -Level Error -Message "Error. You can't have RunUpdateIDEnabled set to True and RunPackageIDEnabled set to True at the same time"
|
||||
|
|
@ -1517,6 +1513,24 @@ if (($Action -eq "ToastReboot:") -AND ($RunPackageIDEnabled -eq "True")) {
|
|||
Write-Log -Level Error -Message "This seems like an unintended configuration. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
if (($Action -eq "ToastRunPackageID:") -AND ($RunApplicationIDEnabled -eq "True")) {
|
||||
Write-Log -Level Error -Message "Error. Conflicting selection in the $Config file"
|
||||
Write-Log -Level Error -Message "You are using the toast notification with RunApplicationIDEnabled set to $RunApplicationIDEnabled, but the action button is set to $Action"
|
||||
Write-Log -Level Error -Message "This seems like an unintended configuration. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
if (($Action -eq "ToastRunUpdateID:") -AND ($RunApplicationIDEnabled -eq "True")) {
|
||||
Write-Log -Level Error -Message "Error. Conflicting selection in the $Config file"
|
||||
Write-Log -Level Error -Message "You are using the toast notification with RunApplicationIDEnabled set to $RunApplicationIDEnabled, but the action button is set to $Action"
|
||||
Write-Log -Level Error -Message "This seems like an unintended configuration. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
if (($Action -eq "ToastReboot:") -AND ($RunApplicationIDEnabled -eq "True")) {
|
||||
Write-Log -Level Error -Message "Error. Conflicting selection in the $Config file"
|
||||
Write-Log -Level Error -Message "You are using the toast notification with RunApplicationIDEnabled set to $RunApplicationIDEnabled, but the action button is set to $Action"
|
||||
Write-Log -Level Error -Message "This seems like an unintended configuration. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
# New checks for conflicting selections. Trying to prevent combinations which will make the toast render without buttons
|
||||
# Added in version 2.1.0
|
||||
if (($ActionButton1Enabled -ne "True") -AND ($ActionButton2Enabled -eq "True")){
|
||||
|
|
@ -1549,21 +1563,6 @@ if (($SnoozeButtonEnabled -eq "True") -AND ($ADPasswordExpirationTextEnabled -eq
|
|||
Write-Log -Level Error -Message "That will result in too much text and the toast notification will render without buttons. Check your config"
|
||||
Exit 1
|
||||
}
|
||||
# New checks for value format
|
||||
if ($Action1 -match "ToastRunApplicationID:" -and (($Action1.trim() -match " ") -or $Action1 -notmatch "ToastRunApplicationID:ScopeId_.+/Application_.+")) {
|
||||
Write-Log -Level Error -Message "Value of Action1 XML config tag isn't in correct format"
|
||||
Write-Log -Level Error -Message "It should be like: ToastRunApplicationID:ScopeId_5197DD71-3116-4878-A26C-EA6155A28E9B/Application_31e422a6-3905-4f83-b9aa-cf1635648e72"
|
||||
Write-Log -Level Error -Message "Value can be found in Software Center by clicking on share icon of application to install"
|
||||
Exit 1
|
||||
}
|
||||
if ($Action2 -match "ToastRunApplicationID:" -and (($Action2.trim() -match " ") -or $Action2 -notmatch "ToastRunApplicationID:ScopeId_.+/Application_.+")) {
|
||||
Write-Log -Level Error -Message "Value of Action2 XML config tag isn't in correct format"
|
||||
Write-Log -Level Error -Message "It should be like: ToastRunApplicationID:ScopeId_5197DD71-3116-4878-A26C-EA6155A28E9B/Application_31e422a6-3905-4f83-b9aa-cf1635648e72"
|
||||
Write-Log -Level Error -Message "Value can be found in Software Center by clicking on share icon of application to install"
|
||||
Exit 1
|
||||
}
|
||||
|
||||
#endregion ######## CHECKS #########
|
||||
|
||||
# Downloading images into user's temp folder if images are hosted online
|
||||
if (($LogoImageFileName.StartsWith("https://")) -OR ($LogoImageFileName.StartsWith("http://"))) {
|
||||
|
|
@ -1650,8 +1649,9 @@ if ($RunUpdateIDEnabled -eq "True") {
|
|||
}
|
||||
|
||||
# Running RunApplicationID function
|
||||
if ($RunApplicationIDValue) {
|
||||
if ($RunApplicationIDEnabled -eq "True") {
|
||||
Write-Log -Message "RunApplicationID set to True. Will allow execution of ApplicationID directly from the toast action button"
|
||||
Write-ApplicationIDRegistry
|
||||
}
|
||||
|
||||
# Running RunPackageID function
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue