Hi all,
I have the following powershell script I have put together to pull remote server adapter details, it is written using v2 as some of our servers are unfortunately still using Windows Sever 2008
I am receiving a 'Method invocation failed because [system.management.automation.psobject] does not contain a method named ‘op_addition’
I believe this may be due to trying to add the results of two psobject values to the same array variable but am not sure if this is true or how to work around the issue
$NicDetails = @()
$FinalList = @()
$lc = 1
Write-host ‘Getting list of servers from AD, this may take a few moments…’
$Servers = (Get-ADComputer -Filter ‘operatingsystem -like “server”-and enabled -eq “true”‘).Name
foreach ($Server in $Servers) {
if(Test-Connection -ComputerName $Server -Count 1 -ea 0) {
write-host ‘Getting NIC details from’$server $lc ‘of’ ($Servers.count)
$NetAdapter = $null
$NicConfig = $null
$NetAdapter = get-ciminstance -classname win32_networkadapter -computername $Server -filter “NetConnectionStatus = 2” | select netconnectionid,deviceid -ea silentlycontinue
$NicConfig = get-ciminstance -classname win32_networkadapterconfiguration -computername $Server -filter “ipenabled = true” | select ipaddress,ipsubnet,defaultipgateway,index
}
foreach ($Nic in $Netadapter){
$NicName = $null
$NicID = $null
$NicName = $Nic.netconnectionid
$NicID = $Nic.deviceid
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name AdapterName -Value $NicName
$OutputObj | Add-Member -MemberType NoteProperty -Name AdapterID1 -Value $NicID
$NicDetails += $OutputObj}
foreach ($Nic in $NicConfig){
$NicIP = $null
$NicSubnet = $null
$NicGW = $Null
$NicIND = $null
$NicIP = $Nic.ipaddress
$NicSubnet = $Nic.ipsubnet
$NicGW = $Nic.defaultipgateway
$OutputObj = New-Object -Type PSObject
$OutputObj | Add-Member -MemberType NoteProperty -Name IP -Value $NicIP
$OutputObj | Add-Member -MemberType NoteProperty -Name SubnetAddresss -Value $NicSubnet
$OutputObj | Add-Member -MemberType NoteProperty -Name DefaultGateway -Value $NicGW
$OutputObj | Add-Member -MemberType NoteProperty -Name AdapterID2 -Value $NicIND
$NicDetails += $OutputObj}
write-host $NicDetails
$FinalList += $NicDetails
$NicDetails = $Null
$lc ++
}
$FinalList | export-csv NicDetails.csv
Many thanks for any help!