piercj2
Enthusiast
Enthusiast

Create new array from existing array data

I have an array, $bigList = @()

it contains for example

VMnamePowerStateOwnerStatus
MyServer1PoweredOnJ.BloggsInstalled
MyServer2PoweredOffM.SmytheDecommissioned
MyServer3PoweredOffM.SmytheInstalled

I want to create a second array if PowerState=PoweredOff and Status=Decommissioned

The second Array contents will be output as a .CSV

What i've come up with is

$smallList = @()

foreach ($row in $bigList){

     if(($bigList.PowerState -match 'PoweredOff') and ($bigList.Status -match 'Decommissioned)){

          $smallListProperty = [ordered] @{

               'VM Name' = $bigList.VMname

               'Owner' = $bigList.Owner

          }

     $smallList += new-object -TypeName psobject -Property $smallListProperty

}

$smallList | export-CSV -path c:\Temp\smallList.csv

It kind of works but the output i'm getting is

VM NameOwner
System.Object[]System.Object[]

Thanks

Tags (2)
Reply
0 Kudos