Array to csv

%3CLINGO-SUB%20id%3D%22lingo-sub-253863%22%20slang%3D%22en-US%22%3EArray%20to%20csv%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-253863%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20creating%20invetnory%20of%20each%20servers%2C%20however%20i%20am%20not%20able%20to%20put%20output%20of%20that%20NIC%20parameter%20to%20main%20array%2C%20it%20showing%20system.object%5B%5D%2C%20can%20you%20help%20me%20to%20put%20convert%20each%20adapter%20macaddress%20into%20my%20main%20csv%20file%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24Hardware%20%3D%40()%3CBR%20%2F%3E%24a%20%3D%20%22%3CSTYLE%3E%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24a%20%3D%20%24a%20%2B%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BBODY%7Bbackground-color%3Apeachpuff%3B%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24a%20%3D%20%24a%20%2B%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BTABLE%7Bborder-width%3A%201px%3Bborder-style%3A%20solid%3Bborder-color%3A%20black%3Bborder-collapse%3A%20collapse%3B%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24a%20%3D%20%24a%20%2B%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BTH%7Bborder-width%3A%201px%3Bpadding%3A%200px%3Bborder-style%3A%20solid%3Bborder-color%3A%20black%3Bbackground-color%3Athistle%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24a%20%3D%20%24a%20%2B%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3BTD%7Bborder-width%3A%201px%3Bpadding%3A%200px%3Bborder-style%3A%20solid%3Bborder-color%3A%20black%3Bbackground-color%3APaleGoldenrod%7D%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%26amp%3Bamp%3Bamp%3Bamp%3Blt%3BBR%20%2F%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%24a%20%3D%20%24a%20%2B%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3Bquot%3B%3C%2FSTYLE%3E%22%3CBR%20%2F%3E%3CBR%20%2F%3E%24i%3D%24env%3Acomputername%3CBR%20%2F%3E%26lt%3B%23%24MB%3D%20Get-WmiObject%20Win32_BaseBoard%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7C%26nbsp%3B%20Select%20Name%2CManufacturer%2CProduct%2CSerialNumber%2CStatus%3CBR%20%2F%3E%24OS%3Dget-WmiObject%20Win32_OperatingSystem%26nbsp%3B%26nbsp%3B%20%7C%20select-object%20CSName%2COSArchitecture%2C%40%7BName%3D%22FreePhysicalMemory%22%3BExpression%3D%7B%20%22%7B0%3AN0%7D%22%20-f%20(%24_.FreePhysicalMemory%20%2F%201MB)%7D%7D%2Ccaption%2C%40%7BName%3D%22TotalVirtualMemorySize%22%3BExpression%3D%7B%20%22%7B0%3AN0%7D%22%20-f%20(%24_.TotalVirtualMemorySize%20%2F%201MB)%7D%7D%2CServicePackMajorVersion%3CBR%20%2F%3E%24BI%20%3DGet-WmiObject%20win32_bios%26nbsp%3B%26nbsp%3B%20%7C%20Select%20Manufacturer%2CName%2CBIOSVersion%2CPrimaryBIOS%2CSMBIOSBIOSVersion%2CSMBIOSMajorVersion%2CSMBIOSMinorVersion%3CBR%20%2F%3E%24SY%3D%20Get-WmiObject%20Win32_ComputerSystemProduct%26nbsp%3B%26nbsp%3B%20%7C%20Select%20Vendor%2CVersion%2CName%2CIdentifyingNumber%2CUUID%3CBR%20%2F%3E%24HD%3D%20Get-WmiObject%20win32_diskDrive%26nbsp%3B%26nbsp%3B%20%7C%20select%20Model%2CSerialNumber%2CInterfaceType%2C%40%7BName%3D%22Size%22%3BExpression%3D%7B%20%22%7B0%3AN0%7D%22%20-f%20(%24_.FileSize%20%2F%201MB)%7D%7D%2CPartitions%20%23%26gt%3B%3CBR%20%2F%3E%24NIC%3DGet-WmiObject%20win32_networkadapter%26nbsp%3B%20%7C%20Select%20Name%2CManufacturer%2CDescription%20%2CAdapterType%2CSpeed%2CMACAddress%2CNetConnectionID%2CIPaddress%3CBR%20%2F%3E%26lt%3B%23%24Mem%3DGet-WmiObject%20Win32_PhysicalMemory%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7C%20select%20BankLabel%2CDeviceLocator%2CCapacity%2CManufacturer%2CPartNumber%2CSerialNumber%2CSpeed%3CBR%20%2F%3E%24PROC%3DGet-WmiObject%20Win32_Processor%26nbsp%3B%26nbsp%3B%20%7C%20Select%20Caption%2CDeviceID%2CNumberOfCores%2CNumberOfLogicalProcessors%3CBR%20%2F%3E%24CS%3DGet-WmiObject%20Win32_ComputerSystem%26nbsp%3B%26nbsp%3B%20%7C%20select-object%20Name%2C%40%7BName%3D%22TotalPhysicalMemory%22%3BExpression%3D%7B%20%22%7B0%3AN0%7D%22%20-f%20(%24_.TotalPhysicalMemory%20%2F%201MB)%7D%7D%2CSystemType%2CDomain%2CDNSHostName%3CBR%20%2F%3E%24PF%3DGet-WmiObject%20-Class%20Win32_pagefileusage%26nbsp%3B%26nbsp%3B%20%7C%20select-object%20Caption%2C%40%7BName%3D%22AllocatedBaseSize%22%3BExpression%3D%7B%20%22%7B0%3AN0%7D%22%20-f%20(%24_.AllocatedBaseSize%20%2F%201MB)%7D%7D%3CBR%20%2F%3E%24NW%3DGet-WmiObject%20-class%20%22Win32_NetworkAdapterConfiguration%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7C%20Where%20%7B%24_.IPEnabled%20-Match%20%22True%22%7D%20%7C%20Select-object%20IPaddress%2CIPSubnet%2CDefaultIPgateway%2CDNSServerSearchOrder%2CDescription%2CDNSDomainSuffixSearchOrder%3CBR%20%2F%3E%24reg%20%3D%20%5BMicrosoft.Win32.RegistryKey%5D%3A%3AOpenRemoteBaseKey('LocalMachine'%2C%20%24i)%3CBR%20%2F%3E%24regKey%3D%20%24reg.OpenSubKey(%22SYSTEM%5C%5CCurrentControlSet%5C%5CServices%5C%5CNetlogon%5C%5CParameters%22%2C%24true)%3CBR%20%2F%3E%24regvalue%3D%24regkey.GetValue('DynamicSiteName')%23%26gt%3B%3CBR%20%2F%3E%24Report%20%3D%20%22%22%20%7C%20Select-Object%20ComputerName%2COSName%2CServicePack%2CTotalPhysicalMemory%2CTotalVirtualMemory%2CSystemType%2CDomain%2CDNSHostName%2CBIManufacturer%2CBISerialNumber%2CBIOSVersion%2CSMBIOSBIOSVersion%2CSVersion%2CModuleName%2CMBSerialNumber%2CUUID%2CDescriptions%2CMACAddres%2CNWIPaddress%2CNWIPSubnet%2CNWDefaultIPgateway%2CNWDNSServerSearchorder%2CNWDescription%2CNWDNSDomainSuffixSearchorder%2CPCaption%2CPDeviceID%2CNumberOfCores%2CNumberOfLogicalProcessors%2Csitename%3CBR%20%2F%3E%26lt%3B%23%24Report.ComputerName%20%3D%20%24OS.CSNAME%3CBR%20%2F%3E%24Report.OSName%3D%20%24OS.caption%3CBR%20%2F%3E%24Report.ServicePack%3D%20%24OS.ServicePackMajorVersion%3CBR%20%2F%3E%24Report.TotalPhysicalMemory%20%3D%20%24CS.TotalPhysicalMemory%3CBR%20%2F%3E%24Report.TotalVirtualMemory%20%3D%24OS.TotalVirtualMemorySize%3CBR%20%2F%3E%24Report.SystemType%20%3D%24CS.SystemType%3CBR%20%2F%3E%24Report.Domain%3D%24CS.Domain%3CBR%20%2F%3E%24Report.DNSHostname%3D%24CS.DNSHostName%3CBR%20%2F%3E%24Report.BIManufacturer%20%3D%20%24BI.Manufacturer%3CBR%20%2F%3E%24Report.BISerialNumber%3D%20%24BI.MSerialNumber%3CBR%20%2F%3E%24Report.BIOSVersion%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24BI.BIOSVersion)%3CBR%20%2F%3E%24Report.SMBIOSBIOSVersion%3D%20%24BI.SMBIOSBIOSVersion%3CBR%20%2F%3E%24Report.SVersion%3D%20%24SY.Version%3CBR%20%2F%3E%24Report.ModuleName%3D%20%24SY.Name%3CBR%20%2F%3E%24Report.MBSerialNumber%3D%20%24SY.IdentifyingNumber%3CBR%20%2F%3E%24Report.UUID%3D%20%24SY.UUID%20%23%26gt%3B%3CBR%20%2F%3E%24mac%20%3D%20%40()%3CBR%20%2F%3Eforeach%20(%24Net%20in%20%24NIC)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%24row%20%3D%20New-Object%20-Type%20PSObject%20-Property%20%40%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%22MAC1%22%20%3D%24Net.MacAddress%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%22desc%22%20%3D%20%24Net.Description%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%24report.Descriptions%20%3D%20%24mac%20%7C%20select%20desc%3CBR%20%2F%3E%24report.Descriptions%3CBR%20%2F%3E%24report.MACAddres%20%3D%20%24mac%20%7C%20select%20MAC1%3CBR%20%2F%3E%24report.MACAddres%3CBR%20%2F%3E%24mac%20%2B%3D%20%24row%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%26lt%3B%23%24nws%20%3D%20%40()%3CBR%20%2F%3Eforeach%20(%24Network%20in%20%24NW)%20%7B%3CBR%20%2F%3E%24row1%20%3D%20new-object%20-type%20PSObject%20-Property%20%40%7B%3CBR%20%2F%3E%3CBR%20%2F%3E%24Report.NWIPaddress%26nbsp%3B%20%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24Network.IpAddress)%3CBR%20%2F%3E%24Report.NWIPSubnet%26nbsp%3B%20%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24Network.IPSubnet)%3CBR%20%2F%3E%24Report.NWDefaultIPgateway%20%3D%5Bstring%5D%3A%3AJoin('%2C'%2C%24Network.DefaultIPGateway)%3CBR%20%2F%3E%24Report.NWDNSServerSearchorder%20%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24Network.DNSServerSearchOrder)%3CBR%20%2F%3E%24Report.NWDNSDomainSuffixSearchorder%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24Network.DNSDomainSuffixSearchorder)%3CBR%20%2F%3E%24Report.NWDescription%3D%20%24Network.Description%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%24Report.PCaption%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24PROC.Caption)%3CBR%20%2F%3E%24Report.PDeviceID%3D%20%24PROC.DeviceID%3CBR%20%2F%3E%24Report.NumberOfCores%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24PROC.NumberOfCores)%3CBR%20%2F%3E%24Report.NumberOfLogicalProcessors%3D%20%5Bstring%5D%3A%3AJoin('%2C'%2C%24PROC.NumberOfLogicalProcessors)%3CBR%20%2F%3E%24Report.Sitename%20%3D%24regvalue%23%26gt%3B%3CBR%20%2F%3E%26nbsp%3B%24Hardware%20%2B%3D%20%24Report%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%24Hardware%20%7C%20export-csv%20%22c%3A%5Cwindows%5Ctemp%5Cscript%5C%24i.csv%22%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-253863%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Occasional Visitor

I am creating invetnory of each servers, however i am not able to put output of that NIC parameter to main array, it showing system.object[], can you help me to put convert each adapter macaddress into my main csv file

 

 

$Hardware =@()
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"

$i=$env:computername
<#$MB= Get-WmiObject Win32_BaseBoard    |  Select Name,Manufacturer,Product,SerialNumber,Status
$OS=get-WmiObject Win32_OperatingSystem   | select-object CSName,OSArchitecture,@{Name="FreePhysicalMemory";Expression={ "{0:N0}" -f ($_.FreePhysicalMemory / 1MB)}},caption,@{Name="TotalVirtualMemorySize";Expression={ "{0:N0}" -f ($_.TotalVirtualMemorySize / 1MB)}},ServicePackMajorVersion
$BI =Get-WmiObject win32_bios   | Select Manufacturer,Name,BIOSVersion,PrimaryBIOS,SMBIOSBIOSVersion,SMBIOSMajorVersion,SMBIOSMinorVersion
$SY= Get-WmiObject Win32_ComputerSystemProduct   | Select Vendor,Version,Name,IdentifyingNumber,UUID
$HD= Get-WmiObject win32_diskDrive   | select Model,SerialNumber,InterfaceType,@{Name="Size";Expression={ "{0:N0}" -f ($_.FileSize / 1MB)}},Partitions #>
$NIC=Get-WmiObject win32_networkadapter  | Select Name,Manufacturer,Description ,AdapterType,Speed,MACAddress,NetConnectionID,IPaddress
<#$Mem=Get-WmiObject Win32_PhysicalMemory    | select BankLabel,DeviceLocator,Capacity,Manufacturer,PartNumber,SerialNumber,Speed
$PROC=Get-WmiObject Win32_Processor   | Select Caption,DeviceID,NumberOfCores,NumberOfLogicalProcessors
$CS=Get-WmiObject Win32_ComputerSystem   | select-object Name,@{Name="TotalPhysicalMemory";Expression={ "{0:N0}" -f ($_.TotalPhysicalMemory / 1MB)}},SystemType,Domain,DNSHostName
$PF=Get-WmiObject -Class Win32_pagefileusage   | select-object Caption,@{Name="AllocatedBaseSize";Expression={ "{0:N0}" -f ($_.AllocatedBaseSize / 1MB)}}
$NW=Get-WmiObject -class "Win32_NetworkAdapterConfiguration"    | Where {$_.IPEnabled -Match "True"} | Select-object IPaddress,IPSubnet,DefaultIPgateway,DNSServerSearchOrder,Description,DNSDomainSuffixSearchOrder
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $i)
$regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\Netlogon\\Parameters",$true)
$regvalue=$regkey.GetValue('DynamicSiteName')#>
$Report = "" | Select-Object ComputerName,OSName,ServicePack,TotalPhysicalMemory,TotalVirtualMemory,SystemType,Domain,DNSHostName,BIManufacturer,BISerialNumber,BIOSVersion,SMBIOSBIOSVersion,SVersion,ModuleName,MBSerialNumber,UUID,Descriptions,MACAddres,NWIPaddress,NWIPSubnet,NWDefaultIPgateway,NWDNSServerSearchorder,NWDescription,NWDNSDomainSuffixSearchorder,PCaption,PDeviceID,NumberOfCores,NumberOfLogicalProcessors,sitename
<#$Report.ComputerName = $OS.CSNAME
$Report.OSName= $OS.caption
$Report.ServicePack= $OS.ServicePackMajorVersion
$Report.TotalPhysicalMemory = $CS.TotalPhysicalMemory
$Report.TotalVirtualMemory =$OS.TotalVirtualMemorySize
$Report.SystemType =$CS.SystemType
$Report.Domain=$CS.Domain
$Report.DNSHostname=$CS.DNSHostName
$Report.BIManufacturer = $BI.Manufacturer
$Report.BISerialNumber= $BI.MSerialNumber
$Report.BIOSVersion= [string]::Join(',',$BI.BIOSVersion)
$Report.SMBIOSBIOSVersion= $BI.SMBIOSBIOSVersion
$Report.SVersion= $SY.Version
$Report.ModuleName= $SY.Name
$Report.MBSerialNumber= $SY.IdentifyingNumber
$Report.UUID= $SY.UUID #>
$mac = @()
foreach ($Net in $NIC)
{
        $row = New-Object -Type PSObject -Property @{
               "MAC1" =$Net.MacAddress
            "desc" = $Net.Description
    
    }


$report.Descriptions = $mac | select desc
$report.Descriptions
$report.MACAddres = $mac | select MAC1
$report.MACAddres
$mac += $row
}

<#$nws = @()
foreach ($Network in $NW) {
$row1 = new-object -type PSObject -Property @{

$Report.NWIPaddress  = [string]::Join(',',$Network.IpAddress)
$Report.NWIPSubnet  = [string]::Join(',',$Network.IPSubnet)
$Report.NWDefaultIPgateway =[string]::Join(',',$Network.DefaultIPGateway)
$Report.NWDNSServerSearchorder = [string]::Join(',',$Network.DNSServerSearchOrder)
$Report.NWDNSDomainSuffixSearchorder= [string]::Join(',',$Network.DNSDomainSuffixSearchorder)
$Report.NWDescription= $Network.Description
}

$Report.PCaption= [string]::Join(',',$PROC.Caption)
$Report.PDeviceID= $PROC.DeviceID
$Report.NumberOfCores= [string]::Join(',',$PROC.NumberOfCores)
$Report.NumberOfLogicalProcessors= [string]::Join(',',$PROC.NumberOfLogicalProcessors)
$Report.Sitename =$regvalue#>
 $Hardware += $Report



$Hardware | export-csv "c:\windows\temp\script\$i.csv"

0 Replies