I have a script which has a declaration of $outputs=@()
& into which a set of properties get added, here is an out out for the same, im getting these added using $output | Add-Member -MemberType Noteproperty -Name “hostname” -Value “$hostname”, similarly for others properties too. im doing an $outputs+=$output to add the appended values,
hostname : SEAPS01
date : 06/14/2011 02:06:36
ApplicationsInstalled : Microsoft SQL Server 2008 Client Tools
but now the problem is that when i add hard disk info to this it gets owerwritten & i recieve an error as the note property already exists, could you please help me out on how to go about & append the HDD properties to the $outputs object
$colItems = get-wmiobject -class “Win32_LogicalDisk” -namespace “root\CIMV2” -computername $compname
$drivecount=(get-wmiobject -class "Win32_LogicalDisk" -namespace "root\CIMV2" | Select-Object drivetype | Measure-Object).count
foreach ($objItem in $colItems){
for($j=0;$j-lt$drivecount;$j++){
if ($objItem.DriveType -eq 3){
# Write to screen
#write-host "Drive Type: " $objItem.DriveType
$drivename=$objItem.Name
# Improve the display of the higher order values of MB and GB
$displayMB = [math]::round($objItem.Size/1024/1024, 2)
$displayGB = [math]::round($objItem.Size/1024/1024/1024, 2)
$strOutPut57 = $displayGB
# Improve the display of the higher order values of MB and GB
$displayMB = [math]::round($objItem.FreeSpace/1024/1024, 2)
$displayGB = [math]::round($objItem.FreeSpace/1024/1024/1024, 2)
$strOutPut58 = $objItem.Name +"\ "+ $displayGB
$strOutPut59 = $objItem.FileSystem
$output | Add-Member -MemberType Noteproperty -Name DriveName[$j] -Value "$drivename"
$output | Add-Member -MemberType Noteproperty -Name FilesystemType[$j] -Value "$strOutPut59"
$output | Add-Member -MemberType Noteproperty -Name Size[$j] -Value "$strOutPut57"
$output | Add-Member -MemberType Noteproperty -Name FreeSpace[$j] -Value "$strOutPut58"
}
}
}
Add-member is not necessary in this case, you can manupulate the output with Select-Object and custom properties
Your example code also be simplified to this (no need to reassign to $outputs and the result is streaming, objects come out of the pipeline once it’s created)