Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Conversation

@breakwaterlabs
Copy link

Powershell 7 does not support -encoding byte on add/get content. Instead it uses the 'asbytestream' switch.

This uses parameter splatting to convert all references to add- and get-content to be compatible regardless of powershell version.

PR Summary

PR Context

Powershell 7 does not support -encoding byte on add/get content. Instead it uses the 'asbytestream' switch.

This uses parameter splatting to convert all references to add- and get-content to be compatible regardless of powershell version.
@breakwaterlabs
Copy link
Author

@microsoft-github-policy-service agree

} elseif ($PSVersionTable.PSVersion.Major -gt "5")
{
$byteParam = @{AsByteStream = $True}
}
Copy link
Author

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.

{
[byte[]] $policyContentInBytes= get-content $path -AsByteStream -Raw
}
[byte[]] $policyContentInBytes = Get-Content $Path -Raw @byteParam
Copy link
Author

Choose a reason for hiding this comment

The 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

[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
Copy link
Author

Choose a reason for hiding this comment

The 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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant