Skip to content

Commit b8a3013

Browse files
Implement Group Policy settings for PSResource Repository (#1730)
1 parent 720074a commit b8a3013

15 files changed

+660
-59
lines changed

doBuild.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@ function DoBuild
3434
Copy-Item -Path "./LICENSE" -Dest "$BuildOutPath"
3535

3636
# Copy notice
37-
Write-Verbose -Verbose -Message "Copying ThirdPartyNotices.txt to '$BuildOutPath'"
37+
Write-Verbose -Verbose -Message "Copying Notice.txt to '$BuildOutPath'"
3838
Copy-Item -Path "./Notice.txt" -Dest "$BuildOutPath"
3939

40+
# Copy Group Policy files
41+
Write-Verbose -Verbose -Message "Copying InstallPSResourceGetPolicyDefinitions.ps1 to '$BuildOutPath'"
42+
Copy-Item -Path "${SrcPath}/InstallPSResourceGetPolicyDefinitions.ps1" -Dest "$BuildOutPath" -Force
43+
44+
Write-Verbose -Verbose -Message "Copying PSResourceRepository.adml to '$BuildOutPath'"
45+
Copy-Item -Path "${SrcPath}/PSResourceRepository.adml" -Dest "$BuildOutPath" -Force
46+
47+
Write-Verbose -Verbose -Message "Copying PSResourceRepository.admx to '$BuildOutPath'"
48+
Copy-Item -Path "${SrcPath}/PSResourceRepository.admx" -Dest "$BuildOutPath" -Force
49+
4050
# Build and place binaries
4151
if ( Test-Path "${SrcPath}/code" ) {
4252
Write-Verbose -Verbose -Message "Building assembly and copying to '$BuildOutPath'"

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "8.0.400"
3+
"version": "8.0.403"
44
}
55
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.Synopsis
6+
Group Policy tools use administrative template files (.admx, .adml) to populate policy settings in the user interface.
7+
This allows administrators to manage registry-based policy settings.
8+
This script installs PSResourceGet Administrative Templates for Windows.
9+
.Notes
10+
The PSResourceRepository.admx and PSResourceRepository.adml files are
11+
expected to be at the location specified by the Path parameter with default value of the location of this script.
12+
#>
13+
[CmdletBinding()]
14+
param
15+
(
16+
[ValidateNotNullOrEmpty()]
17+
[string] $Path = $PSScriptRoot
18+
)
19+
Set-StrictMode -Version 3.0
20+
$ErrorActionPreference = 'Stop'
21+
22+
function Test-Elevated
23+
{
24+
[CmdletBinding()]
25+
[OutputType([bool])]
26+
Param()
27+
28+
# if the current Powershell session was called with administrator privileges,
29+
# the Administrator Group's well-known SID will show up in the Groups for the current identity.
30+
# Note that the SID won't show up unless the process is elevated.
31+
return (([Security.Principal.WindowsIdentity]::GetCurrent()).Groups -contains "S-1-5-32-544")
32+
}
33+
$IsWindowsOs = $PSHOME.EndsWith('\WindowsPowerShell\v1.0', [System.StringComparison]::OrdinalIgnoreCase) -or $IsWindows
34+
35+
if (-not $IsWindowsOs)
36+
{
37+
throw 'This script must be run on Windows.'
38+
}
39+
40+
if (-not (Test-Elevated))
41+
{
42+
throw 'This script must be run from an elevated process.'
43+
}
44+
45+
if ([System.Management.Automation.Platform]::IsNanoServer)
46+
{
47+
throw 'Group policy definitions are not supported on Nano Server.'
48+
}
49+
50+
$admxName = 'PSResourceRepository.admx'
51+
$admlName = 'PSResourceRepository.adml'
52+
$admx = Get-Item -Path (Join-Path -Path $Path -ChildPath $admxName)
53+
$adml = Get-Item -Path (Join-Path -Path $Path -ChildPath $admlName)
54+
$admxTargetPath = Join-Path -Path $env:WINDIR -ChildPath "PolicyDefinitions"
55+
$admlTargetPath = Join-Path -Path $admxTargetPath -ChildPath "en-US"
56+
57+
$files = @($admx, $adml)
58+
foreach ($file in $files)
59+
{
60+
if (-not (Test-Path -Path $file))
61+
{
62+
throw "Could not find $($file.Name) at $Path"
63+
}
64+
}
65+
66+
Write-Verbose "Copying $admx to $admxTargetPath"
67+
Copy-Item -Path $admx -Destination $admxTargetPath -Force
68+
$admxTargetFullPath = Join-Path -Path $admxTargetPath -ChildPath $admxName
69+
if (Test-Path -Path $admxTargetFullPath)
70+
{
71+
Write-Verbose "$admxName was installed successfully"
72+
}
73+
else
74+
{
75+
Write-Error "Could not install $admxName"
76+
}
77+
78+
Write-Verbose "Copying $adml to $admlTargetPath"
79+
Copy-Item -Path $adml -Destination $admlTargetPath -Force
80+
$admlTargetFullPath = Join-Path -Path $admlTargetPath -ChildPath $admlName
81+
if (Test-Path -Path $admlTargetFullPath)
82+
{
83+
Write-Verbose "$admlName was installed successfully"
84+
}
85+
else
86+
{
87+
Write-Error "Could not install $admlName"
88+
}

src/PSGet.Format.ps1xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<TableColumnHeader><Label>Uri</Label></TableColumnHeader>
9595
<TableColumnHeader><Label>Trusted</Label></TableColumnHeader>
9696
<TableColumnHeader><Label>Priority</Label></TableColumnHeader>
97+
<TableColumnHeader><Label>IsAllowedByPolicy</Label></TableColumnHeader>
9798
</TableHeaders>
9899
<TableRowEntries>
99100
<TableRowEntry>
@@ -102,6 +103,7 @@
102103
<TableColumnItem><PropertyName>Uri</PropertyName></TableColumnItem>
103104
<TableColumnItem><PropertyName>Trusted</PropertyName></TableColumnItem>
104105
<TableColumnItem><PropertyName>Priority</PropertyName></TableColumnItem>
106+
<TableColumnItem><PropertyName>IsAllowedByPolicy</PropertyName></TableColumnItem>
105107
</TableColumnItems>
106108
</TableRowEntry>
107109
</TableRowEntries>

src/PSResourceRepository.adml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- (c) 2006 Microsoft Corporation -->
3+
<policyDefinitionResources xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.0" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
4+
<displayName>PSResourceGet Repository Policy</displayName>
5+
<description>This creates an allow list of repositories for PSResourceGet.</description>
6+
<resources>
7+
<stringTable>
8+
<string id="SUPPORTED_Windows11">At least Windows 11*</string>
9+
<string id="PSResourceGetRepository">PSResourceGet Repository Policy</string>
10+
<string id="PSResourceGetRepository_Help">This creates an allow list of repositories for PSResourceGet.</string>
11+
<string id="PSResourceGetRepository_Cat">PSResourceGet Repository Policies</string>
12+
</stringTable>
13+
<presentationTable>
14+
<presentation id="PSResourceGetRepository">
15+
<text>Please create an allow list of repositories using a name value pair like following: Name=PSGallery;Uri=https://www.powershellgallery.com/api/v2</text>
16+
<listBox refId="PSResourceGetRepository_Listbox"/>
17+
</presentation>
18+
</presentationTable>
19+
</resources>
20+
</policyDefinitionResources>

src/PSResourceRepository.admx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- (c) 2006 Microsoft Corporation -->
3+
<policyDefinitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.0" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
4+
5+
<policyNamespaces>
6+
<target prefix="PSResourceRepository" namespace="Microsoft.PoliciesContentPSResourceRepository" />
7+
<using prefix="windows" namespace="Microsoft.Policies.Windows" />
8+
<using prefix="products" namespace="Microsoft.Policies.Products" />
9+
</policyNamespaces>
10+
11+
<resources minRequiredRevision="1.0" />
12+
13+
<supportedOn>
14+
<definitions>
15+
<definition name="SUPPORTED_Windows11" displayName="$(string.SUPPORTED_Windows11)">
16+
<or>
17+
<reference ref="windows:SUPPORTED_Windows11"/>
18+
</or>
19+
</definition>
20+
</definitions>
21+
</supportedOn>
22+
23+
<categories>
24+
<category name="PSResourceGetRepository" displayName="$(string.PSResourceGetRepository_Cat)">
25+
<parentCategory ref="windows:WindowsComponents" />
26+
</category>
27+
</categories>
28+
29+
<policies>
30+
31+
<policy name="PSResourceGetRepository"
32+
class="User"
33+
displayName="$(string.PSResourceGetRepository)"
34+
explainText="$(string.PSResourceGetRepository_Help)"
35+
presentation="$(presentation.PSResourceGetRepository)"
36+
key="SOFTWARE\Policies\Microsoft\PSResourceGetRepository">
37+
<parentCategory ref="PSResourceGetRepository"/>
38+
<supportedOn ref="windows:SUPPORTED_Windows11" />
39+
<elements>
40+
<list id="PSResourceGetRepository_Listbox" key="SOFTWARE\Policies\Microsoft\PSResourceGetRepository" valuePrefix=""/>
41+
</elements>
42+
</policy>
43+
44+
</policies>
45+
</policyDefinitions>

0 commit comments

Comments
 (0)