-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Group Policy settings for PSResource Repository (#1730)
- Loading branch information
1 parent
720074a
commit b8a3013
Showing
15 changed files
with
660 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.400" | ||
"version": "8.0.403" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
<# | ||
.Synopsis | ||
Group Policy tools use administrative template files (.admx, .adml) to populate policy settings in the user interface. | ||
This allows administrators to manage registry-based policy settings. | ||
This script installs PSResourceGet Administrative Templates for Windows. | ||
.Notes | ||
The PSResourceRepository.admx and PSResourceRepository.adml files are | ||
expected to be at the location specified by the Path parameter with default value of the location of this script. | ||
#> | ||
[CmdletBinding()] | ||
param | ||
( | ||
[ValidateNotNullOrEmpty()] | ||
[string] $Path = $PSScriptRoot | ||
) | ||
Set-StrictMode -Version 3.0 | ||
$ErrorActionPreference = 'Stop' | ||
|
||
function Test-Elevated | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([bool])] | ||
Param() | ||
|
||
# if the current Powershell session was called with administrator privileges, | ||
# the Administrator Group's well-known SID will show up in the Groups for the current identity. | ||
# Note that the SID won't show up unless the process is elevated. | ||
return (([Security.Principal.WindowsIdentity]::GetCurrent()).Groups -contains "S-1-5-32-544") | ||
} | ||
$IsWindowsOs = $PSHOME.EndsWith('\WindowsPowerShell\v1.0', [System.StringComparison]::OrdinalIgnoreCase) -or $IsWindows | ||
|
||
if (-not $IsWindowsOs) | ||
{ | ||
throw 'This script must be run on Windows.' | ||
} | ||
|
||
if (-not (Test-Elevated)) | ||
{ | ||
throw 'This script must be run from an elevated process.' | ||
} | ||
|
||
if ([System.Management.Automation.Platform]::IsNanoServer) | ||
{ | ||
throw 'Group policy definitions are not supported on Nano Server.' | ||
} | ||
|
||
$admxName = 'PSResourceRepository.admx' | ||
$admlName = 'PSResourceRepository.adml' | ||
$admx = Get-Item -Path (Join-Path -Path $Path -ChildPath $admxName) | ||
$adml = Get-Item -Path (Join-Path -Path $Path -ChildPath $admlName) | ||
$admxTargetPath = Join-Path -Path $env:WINDIR -ChildPath "PolicyDefinitions" | ||
$admlTargetPath = Join-Path -Path $admxTargetPath -ChildPath "en-US" | ||
|
||
$files = @($admx, $adml) | ||
foreach ($file in $files) | ||
{ | ||
if (-not (Test-Path -Path $file)) | ||
{ | ||
throw "Could not find $($file.Name) at $Path" | ||
} | ||
} | ||
|
||
Write-Verbose "Copying $admx to $admxTargetPath" | ||
Copy-Item -Path $admx -Destination $admxTargetPath -Force | ||
$admxTargetFullPath = Join-Path -Path $admxTargetPath -ChildPath $admxName | ||
if (Test-Path -Path $admxTargetFullPath) | ||
{ | ||
Write-Verbose "$admxName was installed successfully" | ||
} | ||
else | ||
{ | ||
Write-Error "Could not install $admxName" | ||
} | ||
|
||
Write-Verbose "Copying $adml to $admlTargetPath" | ||
Copy-Item -Path $adml -Destination $admlTargetPath -Force | ||
$admlTargetFullPath = Join-Path -Path $admlTargetPath -ChildPath $admlName | ||
if (Test-Path -Path $admlTargetFullPath) | ||
{ | ||
Write-Verbose "$admlName was installed successfully" | ||
} | ||
else | ||
{ | ||
Write-Error "Could not install $admlName" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- (c) 2006 Microsoft Corporation --> | ||
<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"> | ||
<displayName>PSResourceGet Repository Policy</displayName> | ||
<description>This creates an allow list of repositories for PSResourceGet.</description> | ||
<resources> | ||
<stringTable> | ||
<string id="SUPPORTED_Windows11">At least Windows 11*</string> | ||
<string id="PSResourceGetRepository">PSResourceGet Repository Policy</string> | ||
<string id="PSResourceGetRepository_Help">This creates an allow list of repositories for PSResourceGet.</string> | ||
<string id="PSResourceGetRepository_Cat">PSResourceGet Repository Policies</string> | ||
</stringTable> | ||
<presentationTable> | ||
<presentation id="PSResourceGetRepository"> | ||
<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> | ||
<listBox refId="PSResourceGetRepository_Listbox"/> | ||
</presentation> | ||
</presentationTable> | ||
</resources> | ||
</policyDefinitionResources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- (c) 2006 Microsoft Corporation --> | ||
<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"> | ||
|
||
<policyNamespaces> | ||
<target prefix="PSResourceRepository" namespace="Microsoft.PoliciesContentPSResourceRepository" /> | ||
<using prefix="windows" namespace="Microsoft.Policies.Windows" /> | ||
<using prefix="products" namespace="Microsoft.Policies.Products" /> | ||
</policyNamespaces> | ||
|
||
<resources minRequiredRevision="1.0" /> | ||
|
||
<supportedOn> | ||
<definitions> | ||
<definition name="SUPPORTED_Windows11" displayName="$(string.SUPPORTED_Windows11)"> | ||
<or> | ||
<reference ref="windows:SUPPORTED_Windows11"/> | ||
</or> | ||
</definition> | ||
</definitions> | ||
</supportedOn> | ||
|
||
<categories> | ||
<category name="PSResourceGetRepository" displayName="$(string.PSResourceGetRepository_Cat)"> | ||
<parentCategory ref="windows:WindowsComponents" /> | ||
</category> | ||
</categories> | ||
|
||
<policies> | ||
|
||
<policy name="PSResourceGetRepository" | ||
class="User" | ||
displayName="$(string.PSResourceGetRepository)" | ||
explainText="$(string.PSResourceGetRepository_Help)" | ||
presentation="$(presentation.PSResourceGetRepository)" | ||
key="SOFTWARE\Policies\Microsoft\PSResourceGetRepository"> | ||
<parentCategory ref="PSResourceGetRepository"/> | ||
<supportedOn ref="windows:SUPPORTED_Windows11" /> | ||
<elements> | ||
<list id="PSResourceGetRepository_Listbox" key="SOFTWARE\Policies\Microsoft\PSResourceGetRepository" valuePrefix=""/> | ||
</elements> | ||
</policy> | ||
|
||
</policies> | ||
</policyDefinitions> |
Oops, something went wrong.