This repository was archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Add full pwsh7 compatibility #10
Open
breakwaterlabs
wants to merge
1
commit into
PowerShell:master
Choose a base branch
from
breakwaterlabs:fix-pwsh7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ########################################################### | ||
| ########################################################### | ||
| # | ||
| # Group Policy - Registry Policy parser module | ||
| # | ||
|
|
@@ -22,6 +22,14 @@ data LocalizedData | |
| } | ||
|
|
||
| Import-LocalizedData LocalizedData -filename GPRegistryPolicyParser.Strings.psd1 | ||
| # Add compatibility for Powershell Core which does not support 'encoding byte' via splatting | ||
| if ( $PSVersionTable.PSVersion.Major -le "5") | ||
| { | ||
| $byteParam = @{Encoding = "Byte"} | ||
| } elseif ($PSVersionTable.PSVersion.Major -gt "5") | ||
| { | ||
| $byteParam = @{AsByteStream = $True} | ||
| } | ||
|
|
||
| $script:REGFILE_SIGNATURE = 0x67655250 # PRef | ||
| $script:REGISTRY_FILE_VERSION = 0x00000001 #Initially defined as 1, then incremented each time the file format is changed. | ||
|
|
@@ -185,14 +193,7 @@ Function Read-PolFile | |
| $index = 0 | ||
|
|
||
| [string] $policyContents = Get-Content $Path -Raw | ||
| if ( $PSVersionTable.PSVersion.Major -le "5") | ||
| { | ||
| [byte[]] $policyContentInBytes = Get-Content $Path -Raw -Encoding Byte | ||
| } | ||
| elseif ($PSVersionTable.PSVersion.Major -gt "5") | ||
| { | ||
| [byte[]] $policyContentInBytes= get-content $path -AsByteStream -Raw | ||
| } | ||
| [byte[]] $policyContentInBytes = Get-Content $Path -Raw @byteParam | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we can remove the logic from mid-function and instead simply splat the hashtable |
||
|
|
||
| # 4 bytes are the signature PReg | ||
| $signature = [System.Text.Encoding]::ASCII.GetString($policyContents[0..3]) | ||
|
|
@@ -554,7 +555,7 @@ Function Add-RegistryPolicies | |
| foreach ($rp in $RegistryPolicies) | ||
| { | ||
| [Byte[]] $Entry =New-RegistrySettingsEntry -RegistryPolicy $rp | ||
| $Entry | Add-Content -Path $Path -Encoding Byte | ||
| $Entry | Add-Content -Path $Path @byteParam | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -610,8 +611,8 @@ Function New-GPRegistryPolicyFile | |
|
|
||
| New-Item -Path $Path -Force -Verbose -ErrorAction Stop | Out-Null | ||
|
|
||
| [System.BitConverter]::GetBytes($script:REGFILE_SIGNATURE) | Add-Content -Path $Path -Encoding Byte | ||
| [System.BitConverter]::GetBytes($script:REGISTRY_FILE_VERSION) | Add-Content -Path $Path -Encoding Byte | ||
| [System.BitConverter]::GetBytes($script:REGFILE_SIGNATURE) | Add-Content -Path $Path @byteParam | ||
| [System.BitConverter]::GetBytes($script:REGISTRY_FILE_VERSION) | Add-Content -Path $Path @byteParam | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows us to easily make all calls to add/get-content compatible |
||
| } | ||
|
|
||
| <# | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used the same version detection logic merged in earlier commits, but instead of using that to call a function we just define the correct parameter as a hashtable.