Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Need help with inherited powershell code

$
0
0

Hey all so I inherited this code at work. It is suppose to get information for desired computers where I work. However some of the things it tries to pull doesn't always work. The main one is the mac address.

Here's the code:

Function Get-Inventory {

PROCESS {
$ErrorActionPreference = "SilentlyContinue"

$os = Get-WmiObject Win32_OperatingSystem -EA silentlyContinue  –computer $_ 

$bios = Get-WmiObject Win32_BIOS -EA silentlyContinue –computer $_ 

$Network = Get-WmiObject win32_networkadapterconfiguration -EA silentlyContinue  -Filter 'DHCPEnabled = "true"' –computer $_

$make = get-wmiobject win32_computersystem -EA silentlyContinue  –computer $_

$processor = Get-WmiObject Win32_Processor -EA silentlyContinue  -computer $_

$mem = get-wmiobject win32_computersystem -EA silentlyContinue  -computer $_

$disk = Get-WmiObject Win32_LogicalDisk -EA silentlyContinue  -computerName $_ -Filter "DeviceID='C:'" |Select-Object Size,FreeSpace

$output = New-Object PSObject

$output | Add-Member NoteProperty ComputerName $_

$output | Add-Member NoteProperty MACAddress ($Network.MACAddress)

$output | Add-Member NoteProperty Model ($make.Model)

$output | Add-Member NoteProperty BIOSSerial ($bios.SerialNumber)

$output | Add-Member NoteProperty Processor ($processor.name)

$output | Add-Member NoteProperty Memory ([math]::round($mem.totalphysicalmemory/1GB))

$output | Add-Member NoteProperty LocalStorage ([math]::round($disk.Size)/1GB)

$output | Add-Member NoteProperty User ($make.username)

#$output | Add-Member NoteProperty SPVer ($os.ServicePackMajorVersion)

#$output | Add-Member NoteProperty BuildNo ($os.BuildNumber)

$output | Add-Member NoteProperty 32/64BitOS ($os.OSArchitecture)

Write-Output $output

}

}

So all this goes to an excel file.


Here's a snippet of what it out puts:

#TYPE System.Management.Automation.PSCustomObject								
ComputerName	MACAddress	Model	BIOSSerial	Processor	Memory	LocalStorage	User	32/64BitOS
CEIT2552210X023	System.Object[]	4524W1P	MJVBTR1	Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz	16	465.7597618		64-bit
CEIT2552210X033	System.Object[]	4524W1P	MJVBTV6	Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz	16	465.7597618		64-bit
CEIT2552210X014	System.Object[]	4524W1P	MJVBTR5	Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz	16	465.7597618		64-bit
CEIT2552210X018	System.Object[]	4524W1P	MJVBTP9	Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz	16	465.7597618		64-bit
CEIT2552210X015	System.Object[]	4524W1P	MJVBTR6	Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz	16	465.7597618		64-bit
CEIT2552210X025	System.Object[]	4524W1P	MJVBTP4	Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz	16	465.7597618		64-bit
CEIT2552210X036	System.Object[]	4524W1P	MJVBTT2	Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz	16	465.7597618		64-bit

So the problem is that where I need the mac address it says System.object. So does anyone know any functions that would work better to pull the macs.

Thanks like I said I really knew to powershell.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>