Skip to content

Commit

Permalink
Added Spanish Support
Browse files Browse the repository at this point in the history
- Need to fully test
- Fixes #3
  • Loading branch information
VertigoRay committed Jul 27, 2018
1 parent 05e3b69 commit c2fbcd1
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 21 deletions.
29 changes: 29 additions & 0 deletions Examples/ConvertTo-QuserObject.Console_User_Only_ES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Parameters":{
"QuserOutput":{
"Server": "localhost",
"Result": [
" NOMBRE USUARIO NOMBRE SESIÓN ID. ESTADO TIEMPO IN. TIEMPO SESIÓN",
">mabe-b3 console 1 Activo ninguno 7/25/2018 7:46 AM"
]
}
},
"Culture": "es-EC",
"Output": [
{
"Server" : "localhost",
"Username" : "mabe-b3",
"Sessionname" : "console",
"Id" : 1,
"State" : "Activo",
"IdleTime" : {
"Type" : "System.Void",
"Value" : null
},
"LogonTime" : {
"Type" : "System.DateTime",
"Value" : "07/25/2018 07:46:00"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"Parameters": {
"QuserOutput": {
"Server": "localhost",
"Result": [
" NOMBRE USUARIO NOMBRE SESIÓN ID. ESTADO TIEMPO IN. TIEMPO SESIÓN",
">mabe-b3 console 1 Activo ninguno 7/25/2018 7:46 AM",
" otro00 2 Desc 2 7/25/2018 10:51 AM"
]
}
},
"Culture": "es-EC",
"Output": [
{
"Server": "localhost",
"Username": "mabe-b3",
"Sessionname": "console",
"Id": 1,
"State": "Activo",
"IdleTime": {
"Type" : "System.Void",
"Value" : null
},
"LogonTime": {
"Type" : "System.DateTime",
"Value" : "07/25/2018 07:46:00"
}
},
{
"Server": "localhost",
"Username": "otro00",
"Sessionname": "",
"Id": 2,
"State": "Desc",
"IdleTime": {
"Type" : "System.TimeSpan",
"Value" : "0.00:02:00"
},
"LogonTime": {
"Type" : "System.DateTime",
"Value" : "07/25/2018 10:51:00"
}
}
]
}
54 changes: 36 additions & 18 deletions QuserObject/Private/ConvertTo-QuserObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ function ConvertTo-QuserObject {
[CmdletBinding()]
[OutputType([PSObject])]
Param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
[Parameter(
ValueFromPipeline = $true,
Mandatory = $true
)]
[hashtable]
$QuserOutput
)
Expand All @@ -26,6 +29,13 @@ function ConvertTo-QuserObject {
Write-Debug "[QuserObject ConvertTo-QuserObject] Process Bound Parameters: $($MyInvocation.BoundParameters | ConvertTo-Json)"
Write-Debug "[QuserObject ConvertTo-QuserObject] Process Unbound Parameters: $($MyInvocation.UnboundParameters | ConvertTo-Json)"

if ($script:Culture.Parent.Name -and $script:Culture.Parent -eq 'es') {
Write-Debug "[QuserObject ConvertTo-QuserObject] Culture Adjustements: ${script:Culture}"
$QuserOutput.Result[0] = $QuserOutput.Result[0].Replace('.', ' ')
}

Write-Debug "[QuserObject ConvertTo-QuserObject] QuserOutput.Result: $($QuserOutput.Result | Out-String)"

((($QuserOutput.Result) -replace '^>', '') -replace '\s{2,}', ',').Trim() | ForEach-Object {
Write-Debug "[QuserObject ConvertTo-QuserObject] Add Comma, if needed: $_"
if ($_.Split(',').Count -eq 5) {
Expand All @@ -39,37 +49,45 @@ function ConvertTo-QuserObject {
if (-not $header) {
[System.Collections.ArrayList] $parts = @()
foreach ($part in $rowParts) {
$parts.Add((Get-Culture).TextInfo.ToTitleCase($part.ToLower()).Replace(' ', '')) | Out-Null
$parts.Add($script:Culture.TextInfo.ToTitleCase($part.ToLower()).Replace(' ', '')) | Out-Null
}
$header = ($parts -join ',')
Write-Debug "[QuserObject ConvertTo-QuserObject] Processed Header Row"
} else {
# Id
[int] $rowParts[2] = $rowParts[2]

# IdleTime
$getQuserIdleTime = @{
QuserIdleTime = $rowParts[4]
AsDateTime = $script:IdleStartTime
}
$rowParts[4] = Get-QuserIdleTime @getQuserIdleTime

# LogonTime
$rowParts[5] = Get-Date $rowParts[5]

Write-Debug "[QuserObject ConvertTo-QuserObject] Processed Row: $($rowParts -join ',') "

@($header, ($rowParts -join ',')) | ConvertFrom-Csv | ForEach-Object {
Write-Debug "[QuserObject ConvertTo-QuserObject] Pre Output ($(($_ | Measure-Object).Count)): $($_ | Out-String)"
$output = @{
Server = $QuserOutput.Server
Username = [string] $_.Username
Sessionname = [string] $_.Sessionname
Id = [int] $_.Id
State = [string] $_.State
IdleTime = if (-not $_.IdleTime) { $null } else { Get-Date $_.IdleTime }
LogonTime = Get-Date $_.LogonTime
}

$output = @{}

Write-Debug "[QuserObject ConvertTo-QuserObject] Server ($($script:CultureText.Server)): $($QuserOutput.Server)"
$output.Add('Server', ($QuserOutput.Server))

Write-Debug "[QuserObject ConvertTo-QuserObject] Username ($($script:CultureText.Username)): $(([string] $_.$($script:CultureText.Username)))"
$output.Add('Username', ([string] $_.$($script:CultureText.Username)))

Write-Debug "[QuserObject ConvertTo-QuserObject] Sessionname ($($script:CultureText.Sessionname)): $(([string] $_.$($script:CultureText.Sessionname)))"
$output.Add('Sessionname', ([string] $_.$($script:CultureText.Sessionname)))

Write-Debug "[QuserObject ConvertTo-QuserObject] Id ($($script:CultureText.Id)): $(([int] $_.$($script:CultureText.Id)))"
$output.Add('Id', ([int] $_.$($script:CultureText.Id)))

Write-Debug "[QuserObject ConvertTo-QuserObject] State ($($script:CultureText.State)): $(([string] $_.$($script:CultureText.State)))"
$output.Add('State', ([string] $_.$($script:CultureText.State)))

$quserIdleTime = Get-QuserIdleTime @getQuserIdleTime
Write-Debug "[QuserObject ConvertTo-QuserObject] IdleTime ($($script:CultureText.IdleTime)): ${quserIdleTime}"
$output.Add('IdleTime', $quserIdleTime)

Write-Debug "[QuserObject ConvertTo-QuserObject] LogonTime ($($script:CultureText.LogonTime)): $((Get-Date $_.$($script:CultureText.LogonTime)))"
$output.Add('LogonTime', (Get-Date $_.$($script:CultureText.LogonTime)))

$newObject = New-Object PSObject -Property $output
$newObject.PSTypeNames.Insert(0, 'QuserObject')
Expand Down
9 changes: 9 additions & 0 deletions QuserObject/Private/Invoke-Quser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ function Invoke-Quser {
$quser = '{0} /SERVER:{1}' -f (Get-Command 'quser').Path, $Server
Write-Debug "[QuserObject Invoke-Quser] QUSER Command: ${quser}"

if ((Get-Culture) -ne 'en-US') {
$currentCulture = Get-Culture
Set-Culture -CultureInfo 'en-US'
}

try {
$result = (Invoke-Expression $quser) 2>&1
} catch {
$result = $Error[0].Exception.Message
}
Write-Verbose "[QuserObject Invoke-Quser] QUSER Result (${LASTEXITCODE}):`n$($result | Out-String)"

if ($currentCulture) {
$currentCulture | Set-Culture
}

if ($LASTEXITCODE -eq 0) {
Write-Output @{
Server = $Server
Expand Down
6 changes: 6 additions & 0 deletions QuserObject/QuserObject.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
This is the main scaffolding the glues all the pieces together.
#>
$script:Culture = Get-Culture
if (-not ($script:CultureText = Import-LocalizedData -UICulture $script:Culture -FileName 'culture.psd1' -ErrorAction SilentlyContinue)) {
$script:Culture = [System.Globalization.CultureInfo]::GetCultureInfo('en')
$script:CultureText = Import-LocalizedData -UICulture $script:Culture -FileName 'culture.psd1'
}

$public = @( Get-ChildItem -Path "${PSScriptRoot}\Public\*.ps1" -ErrorAction SilentlyContinue )
$private = @( Get-ChildItem -Path "${PSScriptRoot}\Private\*.ps1" -ErrorAction SilentlyContinue )

Expand Down
18 changes: 18 additions & 0 deletions QuserObject/en-US/culture.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @{
# Server = 'Server'
# Username = 'Username'
# Sessionname = 'Sessionname'
# Id = 'Id'
# State = 'State'
# IdleTime = 'IdleTime'
# LogonTime = 'LogonTime'
# }

ConvertFrom-StringData @'
# English strings
Msg1 = "The Name parameter is missing from the command."
Msg2 = "This command requires the credentials of a member of the Administrators group on the computer."
Msg3 = "Use $_ to represent the object that is being processed."
'@
18 changes: 18 additions & 0 deletions QuserObject/en/about_QuserObject.help.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PSTOPIC
about_QuserObject

SHORT DESCRIPTION
Run `quser.exe` and return a proper PowerShell Object.

LONG DESCRIPTION
Run `quser.exe` and return a proper PowerShell Object.
I discussed this on my blog to enhance a StackOverflow answer.
I thought I'd make this into a PowerShell module for ease of use and distribution.

DETAILED DESCRIPTION
Run `quser.exe` and return a proper PowerShell Object.
I discussed this on my blog to enhance a StackOverflow answer.
I thought I'd make this into a PowerShell module for ease of use and distribution.

You can find documentation here:
https://github.com/UNT-CAS/QuserObject
9 changes: 9 additions & 0 deletions QuserObject/en/culture.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@{
Server = 'Server'
Username = 'Username'
Sessionname = 'Sessionname'
Id = 'Id'
State = 'State'
IdleTime = 'IdleTime'
LogonTime = 'LogonTime'
}
18 changes: 18 additions & 0 deletions QuserObject/es-EC/about_QuserObject.help.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PSTOPIC
    about_QuserObject

BREVE DESCRIPCIÓN
    Ejecute `quser.exe` y devuelva un objeto PowerShell adecuado.

DESCRIPCIÓN LARGA
    Ejecute `quser.exe` y devuelva un objeto PowerShell adecuado.
    Discutí esto en mi blog para mejorar una respuesta de StackOverflow.
    Pensé en convertirlo en un módulo de PowerShell para facilitar su uso y distribución.

DESCRIPCIÓN DETALLADA
    Ejecute `quser.exe` y devuelva un objeto PowerShell adecuado.
    Discutí esto en mi blog para mejorar una respuesta de StackOverflow.
    Pensé en convertirlo en un módulo de PowerShell para facilitar su uso y distribución.

    Puede encontrar documentación aquí:
        https://github.com/UNT-CAS/QuserObject
19 changes: 19 additions & 0 deletions QuserObject/es-EC/culture.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @{
# Server = 'Servidor'
# Username = 'NombreUsuario'
# Sessionname = 'NombreSesión'
# Id = 'Id'
# State = 'Estado'
# IdleTime = 'TiempoIn'
# LogonTime = 'TiempoSesión'
# }

ConvertFrom-StringData @'
Server = Servidor
Username = NombreUsuario
Sessionname = NombreSesión
Id = Id
State = Estado
IdleTime = TiempoIn
LogonTime = TiempoSesión
'@
18 changes: 18 additions & 0 deletions QuserObject/es/about_QuserObject.help.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PSTOPIC
    about_QuserObject

BREVE DESCRIPCIÓN
    Ejecute `quser.exe` y devuelva un objeto PowerShell adecuado.

DESCRIPCIÓN LARGA
    Ejecute `quser.exe` y devuelva un objeto PowerShell adecuado.
    Discutí esto en mi blog para mejorar una respuesta de StackOverflow.
    Pensé en convertirlo en un módulo de PowerShell para facilitar su uso y distribución.

DESCRIPCIÓN DETALLADA
    Ejecute `quser.exe` y devuelva un objeto PowerShell adecuado.
    Discutí esto en mi blog para mejorar una respuesta de StackOverflow.
    Pensé en convertirlo en un módulo de PowerShell para facilitar su uso y distribución.

    Puede encontrar documentación aquí:
        https://github.com/UNT-CAS/QuserObject
9 changes: 9 additions & 0 deletions QuserObject/es/culture.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@{
Server = 'Servidor'
Username = 'NombreUsuario'
Sessionname = 'NombreSesión'
Id = 'Id'
State = 'Estado'
IdleTime = 'TiempoIn'
LogonTime = 'TiempoSesión'
}
Loading

0 comments on commit c2fbcd1

Please sign in to comment.