All pastes #941022 Raw Edit

Anonym

public text v1 · immutable
·published 2008-03-13 13:40 UTC
rendered paste body
function get-computers
{
$strCategory = "computer"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")

$colProplist = "name"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
    {
	$objComputer = $objResult.Properties; 
	if($objComputer.name -notlike 0){$objComputer.name}
	}
}

function log([string]$message,[string]$file)
{
$LOGFILE = [System.IO.File]::AppendText($file)
$LOGFILE.WriteLine($message)
[System.Console]::WriteLine($message)
$LOGFILE.Close()
}

function is_up([string]$hostname)
{
 if( ((Get-WmiObject -Class Win32_PingStatus -Filter "Address='$hostname'" -ComputerName localhost|Select-Object -Property StatusCode).StatusCode) -eq 0){return $TRUE} else{return $FALSE}
}

function has_avira([string]$hostname)
{
	$avira=$FALSE
		foreach($app in d:\scripts\get-software.ps1 -srv $hostname)
		{
		if($app -like "Antivir*"){$avira=$TRUE}
		}
		return $avira
}

function wmi_get_property([string]$hostname,[string]$class,[string]$prop)
{
return (Get-WmiObject -Class $class -ComputerName $hostname|Select-Object -Property $prop).$prop
}

function fill_compinfo([object]$compinfo,[string]$hostname)
{
	$compinfo.HostName = $hostname
	$compinfo.IsUp = is_up -hostname $hostname
	if($compinfo.IsUp -eq $FALSE){return $compinfo}
	$compinfo.Avira = has_avira -hostname $hostname
	#$compinfo.InstallTime = wmi_get_property -class Win32_ComputerSystem -hostname $hostname -prop InstallDate
	$compinfo.Manufacturer = wmi_get_property -class Win32_ComputerSystem -hostname $hostname -prop Manufacturer
	$compinfo.Model = wmi_get_property -class Win32_ComputerSystem -hostname $hostname -prop Model
	$compinfo.NumProcs = wmi_get_property -class Win32_ComputerSystem -hostname $hostname -prop NumberOfProcessors
	$compinfo.ProcName = (Get-WmiObject -class Win32_Processor -Computername $hostname |Select-Object -Property Name -Last 1).Name
	$compinfo.OsVersion = wmi_get_property -class Win32_OperatingSystem -hostname $hostname -prop Version
	$compinfo.ServicePack = wmi_get_property -class Win32_OperatingSystem -hostname $hostname -prop ServicePackMajorVersion
	$compinfo.SerialNumber = wmi_get_property -class Win32_Bios -hostname $hostname -prop SerialNumber
	return $compinfo
}

function get_computerinfo()
{
	$utils_asm = [System.Reflection.Assembly]::LoadFrom("d:\sCRIPTS\Utils.dll")
	$t_compinf = $utils_asm.GetType("ComputerInfo")
	
	$list = d:\sCRIPTS\New-GenericObject.PS1  System.Collections.ObjectModel.Collection ComputerInfo
	
		foreach($computer in get-computers)
		{
			Write-Host "Processing $computer"
			$new_compinfo = [System.Activator]::CreateInstance($t_compinf)
			$filled_compinfo = fill_compinfo -compinfo $new_compinfo -hostname $computer
			$list.Add($filled_compinfo)
		}
		return $list
}