-
Notifications
You must be signed in to change notification settings - Fork 0
/
OutputHandlingUsingCSV.ps1
38 lines (37 loc) · 1.39 KB
/
OutputHandlingUsingCSV.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Output Handling Using CSV
# Machine availability check
# Script Author : www.vivekrr.com
$details = @()
$pc = Get-Content $env:USERPROFILE\desktop\pc.txt
foreach ($sys in $pc)
{
if(!(Test-Connection -Cn $sys -BufferSize 16 -Count 1 -ea 0 -quiet))
{
$Result = [ordered]@{
MACHINE_NAME = "$sys"
PING_STATUS = "MACHINE OFFLINE"
OS_NAME = "N/A"
TOTAL_PHYSICALMEMORY = "N/A"
}
$Details += New-Object PSObject -Property $Result
}
else
{
$osname = "N/A"
$physicalmemory = "N/A"
$sysdetails = ""
$sysdetails = Get-WmiObject -Class Win32_computersystem -ComputerName $sys | select -ExpandProperty TotalPhysicalMemory
$osname = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $sys | select -ExpandProperty caption
$physicalmemory = ($sysdetails)/1mb -as [int]
$Result = [ordered]@{
MACHINE_NAME = "$sys"
PING_STATUS = "MACHINE ONLINE"
OS_NAME = "$OSNAME"
TOTAL_PHYSICALMEMORY = "$physicalmemory"
}
$Details += New-Object PSObject -Property $Result
}
}
$date = Get-Date -UFormat "%m-%d-%y"
$pathofcsv = "$env:userprofile\desktop\" + "Ping_Result_" + "$date" + ".csv"
$Details | export-csv -Path $pathofcsv -NoTypeInformation