Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

how to change a special character n a file to a number

$
0
0

I am running a script to obtain data using quser (amended script Get-LoggedOnUsers.ps1)

I have noticed one of the fields sometimes has a fullstop, I would like to check for this and change it to a zero - so that it can be uploaded into a database.

 

the code that is formatting the quser output is below :

process {
    foreach ($Computer in $ComputerName) {
        quser /server:$Computer | Select-Object -Skip 1 | ForEach-Object {
            $CurrentLine = $_.Trim() -Replace '\s+',' ' -Split '\s'
            $HashProps = @{
                UserName = $CurrentLine[0]
                ComputerName = $Computer -replace ".shareprod.org",""
        }

            # If session is disconnected different fields will be selected
            if ($CurrentLine[2] -eq 'Disc') {
            $HashProps.SessionName = 'rdp'
                    $HashProps.Id = $CurrentLine[1]
                    $HashProps.State = $CurrentLine[2]
                    $HashProps.IdleTime = $CurrentLine[3]
                    $HashProps.LogonTime = $CurrentLine[4..6] -join ' '
            } else {
                    $HashProps.SessionName = $CurrentLine[1]
                    $HashProps.Id = $CurrentLine[2]
                    $HashProps.State = $CurrentLine[3]
                    $HashProps.IdleTime = $CurrentLine[4]
                    $HashProps.LogonTime = $CurrentLine[5..7] -join ' '
            }

I tried to add the section below (immediately after the above code)

if ($CurrentLine[3] -eq '.') {
                $HashProps.SessionName = $CurrentLine[1]
                    $HashProps.Id = $CurrentLine[2]
                    $HashProps.State = $CurrentLine[3]
                    $HashProps.IdleTime = '0'
                    $HashProps.LogonTime = $CurrentLine[5..7] -join ' '
        }

which isnt making any difference to the output file

 

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles