Repository navigation
Expand file tree
/
Copy pathInstall-Extension.ps1
More file actions
72 lines (64 loc) · 3.57 KB
/
Copy pathInstall-Extension.ps1
File metadata and controls
72 lines (64 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[CmdletBinding(DefaultParametersetName = 'Install')]
param(
# Use UpdateSearchString or UpdateID and RevisionNumber to find the Update
[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'Install')] [string]$SQLServer, # e.g. = sqlserver.domain.com
[Parameter(Position = 1, Mandatory = $true, ParameterSetName = 'Install')] [string]$SQLDBName, # e.g. = SUSDB
[Parameter(Mandatory = $false, ParameterSetName = 'Uninstall')] [switch]$Uninstall
)
if ($PsCmdLet.ParameterSetName -eq "Uninstall") {
Get-ChildItem -Path "$($ENV:SMS_ADMIN_UI_PATH)\..\..\XmlStorage\Extensions\Actions" -Recurse -Filter "ShowApplicabilityRule*.xml" | Remove-Item
Get-ChildItem -Path "$($ENV:SMS_ADMIN_UI_PATH)\..\..\XmlStorage\Tools" -Recurse -Filter "Show-ApplicabilityRule.ps1" | Remove-Item
}
else {
$Extension = @"
<ActionDescription Class="Executable" DisplayName="Show Applicability Rule" MnemonicDisplayName="Show Applicability Rule" Description="Displays the applicability rule for a selected update" SqmDataPoint="53">
<ShowOn>
<string>DefaultHomeTab</string>
<string>ContextMenu</string>
</ShowOn>
<ResourceAssembly>
<Assembly>AdminUI.SoftwareUpdateProperties.dll</Assembly>
<Type>Microsoft.ConfigurationManagement.AdminConsole.SoftwareUpdateProperties.Properties.Resources.resources</Type>
</ResourceAssembly>
<ImagesDescription>
<ResourceAssembly>
<Assembly>AdminUI.UIResources.dll</Assembly>
<Type>Microsoft.ConfigurationManagement.AdminConsole.UIResources.Properties.Resources.resources</Type>
</ResourceAssembly>
<ImageResourceName>SUM_Update</ImageResourceName>
</ImagesDescription>
<Executable>
<FilePath>"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"</FilePath>
<Parameters>-ExecutionPolicy ByPass -File "#PATHTOSCRIPT#" -SQLServer "#SQLSERVER#" -SQLDBName "#SUSDB#" #PARAMS# </Parameters>
</Executable>
</ActionDescription>
"@
Push-Location $PSScriptRoot
#Create Tools Folder and copy Show-ApplicabilityRule.ps1 into it
$ToolsFolder = New-Item -Path "$($ENV:SMS_ADMIN_UI_PATH)\..\..\XmlStorage\" -Name "Tools" -ItemType "directory" -Force
Copy-Item .\Show-ApplicabilityRule.ps1 $ToolsFolder
$PathToScript = "$ToolsFolder\Show-ApplicabilityRule.ps1"
#Create GUID Folder and copy ShowApplicabilityRule.xml
$Guids = ("Office_365_Updates", "ef93deea-a0bc-4f36-9b48-a510ac5340eb"),
("All_Software_Updates", "5360fd7a-a1c4-428f-91c9-89a4c5565ce1"),
("All_Windows_10_Updates", "6d833cef-aa77-4018-943c-627979f5905c") | ForEach-Object { [pscustomobject]@{Name = $_[0]; Guid = $_[1] } }
Foreach ($Guid in $Guids) {
Write-Host "Create Extension for $($Guid.Name)"
$GuidFolder = New-Item -Path "$($ENV:SMS_ADMIN_UI_PATH)\..\..\XmlStorage\Extensions\Actions" -Name "$($Guid.Guid)" -ItemType "directory" -Force
$TempXML = $null
[xml]$TempXML = $Extension
$TempXML.SelectNodes("//Parameters") | % {
$_."#text" = $_."#text".Replace("#PATHTOSCRIPT#", $PathToScript)
$_."#text" = $_."#text".Replace("#SQLSERVER#", $SQLServer)
$_."#text" = $_."#text".Replace("#SUSDB#", $SQLDBName)
if ($($Guid.Name) -eq "All_Windows_10_Updates") {
$PARAMS = '-UpdateSearchString "##SUB:LocalizedDisplayName##"'
}
else {
$PARAMS = '-UpdateID "##SUB:CI_UniqueID##" -RevisionNumber "##SUB:RevisionNumber##"'
}
$_."#text" = $_."#text".Replace("#PARAMS#", $PARAMS)
}
$TempXML.Save("$GuidFolder\ShowApplicabilityRule.xml")
}
}