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

merge for out put

$
0
0

want to merge both scripts (i.e for uptime of all servers and and hostname and disk script for all servers)
the out should be like

ip address       days       hours         mins        sec           Hostname       Diskspace
192.168.0.50 17Day(s),18Hour(s),9Min(s),17Seconds    server_001      c: 20.00 GB D:20.00Gb E:10.00Gb

 

$servers = Get-Content C:\Servers.txt
foreach ($s in $servers)
{
try
{
$a=Get-WmiObject -ComputerName $s -Class Win32_OperatingSystem -ErrorAction ‘Stop’
$b = $a.convertToDateTime($a.Lastbootuptime)
[TimeSpan]$LastBoot = New-TimeSpan $b $(Get-Date)
(‘{0} {1}Day(s),{2}Hour(s),{3}Min(s),{4}Seconds’ -f $s,$LastBoot.Days,$lastboot.Hours,$LastBoot.Minutes,
$LastBoot.Seconds) | out-file C:\UptimeReport.txt -append -Encoding ascii
}
Catch
{
(‘{0} Server is notreachable’ -f $s)| Out-File C:\offline.txt -Append -Encoding ascii
}
}

-------------------------------------------------


foreach ($computer in (Get-Content -Path C:\servers.txt))
{
$hostname = Get-WmiObject Win32_Computersystem Name |
Select-Object -ExpandProperty Name

$disks = Get-WmiObject Win32_LogicalDisk  |
foreach {
"$($_.DeviceID) : $($_.FreeSpace / 1GB ) GB"
}
New-Object -TypeName psObject -Property @{
Hostname = $hostname
Disks = $disks  
}
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles