Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

How to remove characters from output

$
0
0

Hi,

I have a powershell script that gives the below output

@{Days=88}

Basically, I am comparing the difference in Lastbootuptime with Get-date for a bunch of computers and doing a new-timespan (I could not find a better way, please let me know if there is a simpler and better way to do it). Anyway, I just need the [int] value from the output, which is 88 . I want to then write a if statement and then compare that int value if it is greater than 35days.

Here is my script that I wrote.

$Filepath = Read-host “Enter ServerList File Path”
$Serverlist = Get-content -Path $Filepath
write-host $Serverlist.Count “Servers”
$a = Get-date -Format G
Foreach ($server in $Serverlist)
{
$x = Invoke-command -computername $server {(Get-WmiObject Win32_OperatingSystem).LastBootUpTime}
$y = [System.Management.ManagementDateTimeConverter]::ToDateTime($x)
$b = New-TimeSpan -Start $y -End $a | Select Days
write-host $Server
Write-host $b
}

Thanks in advance.


Viewing all articles
Browse latest Browse all 13067

Trending Articles