-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathInstallPSResourceGetPolicyDefinitions.ps1
88 lines (78 loc) · 2.72 KB
/
InstallPSResourceGetPolicyDefinitions.ps1
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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"
}