Forked from AndySchneiderDev-zz/ShowSessionState.ps1
Last active
August 29, 2015 14:26
-
-
Save rwilkes/e65fbc68c3717a558fe5 to your computer and use it in GitHub Desktop.
PowerShell Session State Demonstration
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
function Show-SessionStateDemo | |
{ | |
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
$Server, | |
[Parameter()] | |
$Database, | |
[Parameter()] | |
$Query | |
) | |
begin { | |
$privateServerVariable = '_privServer' | |
if($Server) { | |
$PSCmdlet.SessionState.PSVariable.Set($privateServerVariable,$Server) | |
} | |
else { | |
try { | |
$Server = $PSCmdlet.SessionState.PSVariable.GetValue($privateServerVariable).ToString() | |
} | |
Catch {Throw 'The parameter "Server" is required'} | |
} | |
} | |
process { | |
[psobject]@{ | |
'Database' = $Database | |
'Server' = $Server | |
'Query' = $Query | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment