-
Notifications
You must be signed in to change notification settings - Fork 100
Implement Group Policy settings for PSResource Repository #1730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6af98c8
Add group policy files and update find to honor policy
adityapatwardhan c5845b3
Show allowed by policy on PSResourceRepositoryInfo
adityapatwardhan 83cbc28
Add GP checks for all operations
adityapatwardhan 3eab547
Add test file
adityapatwardhan 076d164
Add tests for Group Policy Enforcement
adityapatwardhan 90f842c
Fix operations
adityapatwardhan 70a6c7c
Remove Platform Not Supported Exception
adityapatwardhan 2a03c90
Do not throw when GP not enabled
adityapatwardhan 1523faa
Remove throw
adityapatwardhan 04d23c6
Fix non-windows test
adityapatwardhan 89e9349
CR feedback
adityapatwardhan 2a63329
Fix non-windows check
adityapatwardhan a2ee479
Add example for setting in ADML
adityapatwardhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hashtable. HKLM:SOFTWARE\Policies\Microsoft\PSResourceGet</text> | ||
<listBox refId="PSResourceGetRepository_Listbox"/> | ||
</presentation> | ||
</presentationTable> | ||
</resources> | ||
</policyDefinitionResources> |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.