Array to csv

Copper Contributor

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