$file = ""
@(foreach($comp in Get-Content $file)
{
Write-Host " Getting Info for Server [$Comp]" -fore GREEN
$myobj = "" | Select-Object Name,BusinessSegment,ntrtscan,uptime
$myobj.Name = $comp
# Get RegKey
$regKeyPath = "software\mhhs"
$HKLM = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $comp)
$subKey = $HKLM.OpenSubKey($regKeyPath,$false)
$myobj.BusinessSegment = $subKey.GetValue('BusinessSegment')
# Get Service State
$myobj.ntrtscan = (Get-WmiObject Win32_Service -ComputerName $comp -filter "Name='ntrtscan'").State
# Get Uptime
$lastReboot = (Get-WmiObject Win32_OperatingSystem -ComputerName $comp).LastBootUpTime.Split(".")[0]
$uptime = (Get-Date).Subtract([system.DateTime]::ParseExact($lastReboot,"yyyyMMddHHmmss",$null)).days
$myobj.uptime = $uptime
# Return Object
$myobj
}) | export-Csv output.csv -noType
|