I would like to integrate Test-Connection command into my existing script id like it it to test if machine is online if online continue working, if machine is offline dump offline machines into the Results.cvs file
Secondly , is there a way with Get-Credential to test local IP , to know rest of the IPs or computers are remote ?
here is my existing script :
#Define parameters
param(
[String[]]$ComputerName=$env:computername,
[String]$FilePath = "C:\Users\gdrews\Downloads\ComputerInfo.txt",
[switch]$LogReport
)
#Define function to generate report.
function Get-ComputerInfo
{ $c = get-credential administrator
foreach ($Comp in $ComputerName)
#if (test-connection $Comp -quiet -count 1)
{
Write-host "Working on $Comp"
$Date = Get-Date
$CompInfo = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Comp -credential $c
$OSInfo = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Comp -credential $c
$Bios = Get-WmiObject Win32_BIOS -ComputerName $Comp -credential $c
$CPUInfo = Get-WmiObject Win32_Processor -ComputerName $Comp -credential $c
$Computer = $CompInfo.Name
$Domain = $CompInfo.Domain
$User = $CompInfo.UserName
$OS = $OSInfo.Caption
$Installdate = $OSInfo.ConvertToDateTime($OSInfo.installDate)
$Model = $CompInfo.Model
$CPU = $CPUInfo.Name
$RAM = "{0:n2} GB" -f ($CompInfo.TotalPhysicalMemory/1gb)
$SystemType = $CompInfo.SystemType
$uptime = Get-Uptime
$Disk = GetDriveInfo $Comp
""
"PC Name : $Computer"
"User Name : $User"
"Model : $Model"
"Domain : $Domain"
"OS : $OS"
"Uptime : $uptime"
"Install Date : $Installdate"
"RAM : $RAM"
"Disk : $Disk"
"SystemType : $SystemType"
"CPU : $CPU"
#"User information collected on : $date"
""
}
}
function GetDriveInfo{
Param($Comp)
# Get disk sizes
$logicalDisk = Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" -ComputerName $comp -credential $c
foreach($disk in $logicalDisk)
{
$diskObj = "" | Select-Object Disk,Size,FreeSpace
$diskObj.Disk = $disk.DeviceID
$diskObj.Size = "{0:n0} GB" -f (($disk | Measure-Object -Property Size -Sum).sum/1gb)
$diskObj.FreeSpace = "{0:n0} GB" -f (($disk | Measure-Object -Property FreeSpace -Sum).sum/1gb)
$text = "{0} {1} Free: {2}" -f $diskObj.Disk,$diskObj.size,$diskObj.Freespace
$msg += $text + " `r`n " + " `r`n "
}
$msg
}
function Get-Uptime {
$OSInfo = Get-WmiObject win32_operatingsystem
$uptime = (Get-Date) - ($OSInfo.ConvertToDateTime($OSInfo.lastbootuptime))
$Display = "Uptime: " + $Uptime.Days + " days, " + $Uptime.Hours + " hours, " + $Uptime.Minutes + " minutes"
Write-Output $Display
}
#Entry point to script
Get-ComputerInfo
if($LogReport)
{
Get-ComputerInfo | Out-File -FilePath $FilePath -encoding ASCII -Append
}