Advanced Event 9 :
<#
.DESCRIPTION
This script perform inventory and export data to xml.
.LINK
http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/12/the-2012-scripting-games-advanced-event-9-perform-an-inventory.aspx
#>
function Create-XML
{
Param ([Parameter(Mandatory=$true,
ValueFromPipeline=$true)]$object)
@"
<ComputerInfo>
"@
foreach ($p in $object |Get-Member -type *Property )
{
$Name = $p.Name
$Value = $Object.$Name
@"
`t<$Name>$Value</$Name>`n
"@
}
@"
</ComputerInfo>
"@
}
function HumanReadSize
{
Param ([long]$Size)
if ($Size -ge 1Gb )
{
return ("{0:N2}" -f ($Size / 1Gb) + " GigaBytes")
}
elseif ($Size -ge 1Mb )
{
return ("{0:N2}" -f ($Size / 1Mb ) + " MegaBytes")
}
elseif ($Size -ge 1Kb )
{
return ("{0:N2}" -f ($Size / 1Kb ) + " KiloBytes")
}
elseif (($Size -ge 0 ) -and ($Size -lt 1Kb))
{
return ("{0:N0}" -f ($Size) + " Bytes")
}
}
$sum=0
$os= Get-WmiObject Win32_OperatingSystem
$comp = Get-WmiObject win32_ComputerSystem
$procs = Get-WmiObject win32_Processor
$nets = Get-WmiObject win32_networkadapter -Filter "netenabled = true"
Get-WmiObject win32_physicalmemory | where {( $_.typedetail -ne 4096 )} | foreach {$sum += $_.capacity }
$output = New-Object PSObject
$output | Add-Member noteproperty ComputerName ($comp.Name)
$output | Add-Member noteproperty DomainName ($comp.Domain)
$output | Add-Member noteproperty Manufacturer ($comp.Manufacturer)
$output | Add-Member noteproperty ComputerModel ($comp.Model)
$output | Add-Member noteproperty NumberofProcessors ($comp.NumberOfProcessors)
$output | Add-Member noteproperty Numberofcores ($comp.NumberOfLogicalProcessors)
$i=1
foreach ($proc in $procs)
{
$output | Add-Member noteproperty "Speedofprocessors$i" ($proc.MaxClockSpeed)
$output | Add-Member noteproperty "ProcessorID$i" ($proc.ProcessorID)
$i +=1
}
$b=1
foreach ($net in $nets)
{
$output | Add-Member noteproperty "MACAddress$b" ($net.MACAddress)
$b += 1
}
$output | Add-Member noteproperty Version ($os.Version)
$output | Add-Member noteproperty Memory (HumanReadSize $sum)
$filepath = $env:userprofile + "\Documents\" + ($comp.Name) + "." + ($comp.Domain) + "." + (Get-date).tostring("yyyyMMdd") + ".xml"
$output | create-xml | Out-file $filepath
<#
.DESCRIPTION
This script perform inventory and export data to xml.
.LINK
http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/12/the-2012-scripting-games-advanced-event-9-perform-an-inventory.aspx
#>
function Create-XML
{
Param ([Parameter(Mandatory=$true,
ValueFromPipeline=$true)]$object)
@"
<ComputerInfo>
"@
foreach ($p in $object |Get-Member -type *Property )
{
$Name = $p.Name
$Value = $Object.$Name
@"
`t<$Name>$Value</$Name>`n
"@
}
@"
</ComputerInfo>
"@
}
function HumanReadSize
{
Param ([long]$Size)
if ($Size -ge 1Gb )
{
return ("{0:N2}" -f ($Size / 1Gb) + " GigaBytes")
}
elseif ($Size -ge 1Mb )
{
return ("{0:N2}" -f ($Size / 1Mb ) + " MegaBytes")
}
elseif ($Size -ge 1Kb )
{
return ("{0:N2}" -f ($Size / 1Kb ) + " KiloBytes")
}
elseif (($Size -ge 0 ) -and ($Size -lt 1Kb))
{
return ("{0:N0}" -f ($Size) + " Bytes")
}
}
$sum=0
$os= Get-WmiObject Win32_OperatingSystem
$comp = Get-WmiObject win32_ComputerSystem
$procs = Get-WmiObject win32_Processor
$nets = Get-WmiObject win32_networkadapter -Filter "netenabled = true"
Get-WmiObject win32_physicalmemory | where {( $_.typedetail -ne 4096 )} | foreach {$sum += $_.capacity }
$output = New-Object PSObject
$output | Add-Member noteproperty ComputerName ($comp.Name)
$output | Add-Member noteproperty DomainName ($comp.Domain)
$output | Add-Member noteproperty Manufacturer ($comp.Manufacturer)
$output | Add-Member noteproperty ComputerModel ($comp.Model)
$output | Add-Member noteproperty NumberofProcessors ($comp.NumberOfProcessors)
$output | Add-Member noteproperty Numberofcores ($comp.NumberOfLogicalProcessors)
$i=1
foreach ($proc in $procs)
{
$output | Add-Member noteproperty "Speedofprocessors$i" ($proc.MaxClockSpeed)
$output | Add-Member noteproperty "ProcessorID$i" ($proc.ProcessorID)
$i +=1
}
$b=1
foreach ($net in $nets)
{
$output | Add-Member noteproperty "MACAddress$b" ($net.MACAddress)
$b += 1
}
$output | Add-Member noteproperty Version ($os.Version)
$output | Add-Member noteproperty Memory (HumanReadSize $sum)
$filepath = $env:userprofile + "\Documents\" + ($comp.Name) + "." + ($comp.Domain) + "." + (Get-date).tostring("yyyyMMdd") + ".xml"
$output | create-xml | Out-file $filepath
No comments:
Post a Comment