Skip to content

Instantly share code, notes, and snippets.

@santisq
Created January 27, 2024 05:59
Show Gist options
  • Save santisq/430de08cb980be44ed3365f760094737 to your computer and use it in GitHub Desktop.
Save santisq/430de08cb980be44ed3365f760094737 to your computer and use it in GitHub Desktop.
not so private powershell
$private:hash = @{ foo = 'bar' }
& {
$type = $ExecutionContext.SessionState.PSVariable.GetType()
$method = $type.GetMember('GetValueAtScope', [System.Reflection.BindingFlags] 'Instance, NonPublic')
$method.Invoke($ExecutionContext.SessionState.PSVariable, ('hash', 'global'))['foo'] = 'nope'
}
$private:hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment