SecureString
to plain text conversion using NetWorkCredential
instead of marshalling
#59
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.
PR Summary
Context
Sent the PR to the wrong repo 😅. Also added a few more changes to
Add-EnvPath
(the logic could be simplified).Changes
Adding
tools/Modules
andoutput
folder to.gitignore
, otherwise the modules needed for CI/CD and the released module would get pushed to repository.Added
launch
file for easier debugging, i.e.: Ctrl+Shift+Enter opens a newpwsh
with the module already loaded.Added
tasks
file, easier building, i.e.: Ctrl+Shift+B runsbuild.ps1
and F1 ->Run Test Task
runsbuild.ps1 -Task Test
.Using
NetworkCredential
to decrypt the secure string instead of marshalling. This method properly handles the unmanaged memory, makes it simpler and correctly frees the unmanaged memory.Otherwise, if marshalling:
PtrToStringAuto
should bePtrToStringBSTR
instead to avoid encoding issues.finally
block in the function that calls[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
to free the unmanaged memory, otherwise the plain text password lives in unmanaged memory while thepwsh
process is alive.Both points above are correctly managed by
NetworkCredential
.Using
[System.IO.Path]::PathSeparator
instead of;
to split the path in case you want to make this module compatible with Linux in the future (its separator is:
).Trim()
to remove any extra trailing or leading whitespace from each token and then filtering any token that could be purely white space, i.e.:Same change to split using
[System.IO.Path]::PathSeparator
.Checklist