PowerShell - filter column output / split column output

Hello again,

I need some help changing the output of a column in my script.

I've a script that gets last update time by reading a registry key. The value returned is in form of "yyyy/mm/dd hh:mm:ss", I need to split it into 2 columns. If not possible, just remove the hour would be enough.

## Library script
#
. "C:\library.ps1"
#
##BEGIN
#
#
#Set list path
$file= "C:\wklist.txt"
#
#
cls
Write-Host "Aguarde..."
#
#Get credential
$cre1 = Get-Credential "Enter Credential"
#Loads list content
Get-Content $file |
ForEach-Object {
    #ICMP test 4 packets
    If(Test-Connection -ComputerName $_ -count 4 -Quiet ){
        Invoke-Command -cn $_ -ScriptBlock {
            Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install" -ErrorAction SilentlyContinue
        } -Credential $cre1
    }
    #If ICMP fails
    Else{New-Object PSObject -Property @{PSComputerName="$_";LastSuccessTime="OFFLINE"}
    }
} | Select PSComputerName,LastSuccessTime | Sort PSComputerName,LastSuccessTime | Export-Csv "c:\temp\lastupdate_result.csv" -NoTypeInformation
#
Pause
#
#
##END

In Test-Connection I need the 4 samples because I will collect data on a very big network.


  • Edited by H Souza 1 hour 42 minutes ago
August 27th, 2015 1:29am

PS > $dt=[datetime]'1995/11/21 10:45:55'
PS > $dt.ToShortDateString()
11/21/1995
PS > $dt.ToShortTimeString()
10:45 AM
PS >

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 3:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics