=Modified SessionData to work on Linux
This commit is contained in:
parent
2d858a8a06
commit
55f5acc0f2
|
@ -42,12 +42,18 @@ param([string]$String,[switch]$AsPowershellCommandLine)
|
|||
return "$(if($AsPowershellCommandLine){"$(Get-PowerShellPath) -EncodedCommand "} )$([Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($String)))"
|
||||
}
|
||||
|
||||
function Get-TempPath {
|
||||
#New-TemporaryFile | ForEach-Object { Remove-Item $_; $_.DirectoryName }
|
||||
[System.IO.Path]::GetTempPath()
|
||||
}
|
||||
|
||||
class SessionData {
|
||||
static [hashtable]$Data = [ordered]@{}
|
||||
static [string]$Path = $null
|
||||
|
||||
static [void] Init() {
|
||||
if( -not [SessionData]::Data.SessionID ) {
|
||||
if( Get-Command -Name Get-CimInstance -ErrorAction SilentlyContinue ) {
|
||||
[SessionData]::Data.SessionID =
|
||||
Get-CimInstance -ClassName Win32_Service -Filter 'State="Running" AND DisplayName like "%[_]%"' -Property 'DisplayName','Name' |
|
||||
Select-Object -ExpandProperty DisplayName |
|
||||
|
@ -55,15 +61,33 @@ class SessionData {
|
|||
$_ -split '_' | Select-Object -Last 1
|
||||
} |
|
||||
Where-Object { $_ -notin ('agent') } |
|
||||
Select-Object -First 1
|
||||
|
||||
Select-Object -First 1 |
|
||||
Out-String
|
||||
} else {
|
||||
$local:p = Get-Process -PID $global:PID
|
||||
$local:t_p = $null
|
||||
do {
|
||||
$t_p = $null
|
||||
if( $p.Parent.Id ) {
|
||||
$t_p = Get-Process -Id $($p.Parent.Id) | Where-Object StartTime
|
||||
}
|
||||
if( $t_p ) {
|
||||
$p = $t_p
|
||||
}
|
||||
} while ($t_p)
|
||||
[SessionData]::Data.SessionID = "$(
|
||||
$p.StartTime.ToString("yyyyMMddHHmmss")
|
||||
)-$(
|
||||
$p.SessionId
|
||||
)"
|
||||
}
|
||||
[SessionData]::Data.CreateTimestamp = Get-Date
|
||||
|
||||
[SessionData]::Path = Join-Path $env:tmp "session.store.$([SessionData]::Data.SessionID).xmlcli"
|
||||
[SessionData]::Path = Join-Path $(Get-TempPath) "session.store.$([SessionData]::Data.SessionID).xmlcli"
|
||||
}
|
||||
}
|
||||
|
||||
static [int] GetSessionID() {
|
||||
static [string] GetSessionID() {
|
||||
if( -not [SessionData]::Data.SessionID ) {
|
||||
[SessionData]::Init()
|
||||
|
||||
|
|
Loading…
Reference in New Issue