Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

PowerCLI Filter $results to not include certain results

$
0
0

I have a script that I am running for the backup team and it runs well but I need to streamline it to not return results of a certain query.

 

$report = @()
$report += Get-View -ViewType VirtualMachine -Filter @{'Runtime.PowerState'='poweredOn'} |
Select -First 20 Name,    @{N='Datacenter';E={        $parent = Get-View -Id $_.Parent -Property Name,Parent        while($parent -isnot [VMware.Vim.Datacenter] -and $parent){            $parent = Get-View -Id $parent.Parent -Property Name,Parent        }        if($parent){            $parent.Name        }}},    @{N="NetworkerPolicy";E={        $caEntry = $_.AvailableField | Where-Object {$_.Name -eq 'Last EMC vProxy Backup'}        $script:policy = ($_.CustomValue | where{$_.Key -eq $caEntry.Key}).Value        $script:policy        }},    @{N="Daily Status";E={         if(($script:policy -eq 'Replicated System') -or         ($script:policy -eq 'DEV-QA System') -or         ($script:policy -eq 'Client Backup') -or         ($script:policy -eq 'Restore/Rebuilt System') -or         ($script:policy -eq 'Decommed') -or        ($script:policy -eq 'Replication Machines') -or        ($script:policy -eq 'NetWorker Proxy (Do Not Backup)') -or        ($script:policy -eq 'Restored Machine') -or        ($script:policy -eq 'Desktop System')){             Write-Output "-"            }        elseif        ($script:policy -like "*StartTime=$DayBefore*"){            Write-Output "Success"            }        elseif        ($script:policy -like "*StartTime=$ChkDATE*"){            Write-Output "Success"            }        else        {            Write-Output "Failure"            }    }}
$report | Select -Property $Properties | Sort Name | Export-Csv $FileCSV -NoTypeInformation

 

I have tried Select, Select-String, Where, Where-Object, etc.... in numerous places.  Ideally I would like to filter the @networkerpolicy section to basically have the entire $results exclude Systems that are returned as part of the @networkerpolicy that return results -eq 'Replicated System', 'DEV-QA System', 'Client Backup', 'Restore/Rebuilt System','Decommed','Replication Machines',''NetWorker Proxy (Do Not Backup)','Restored Machine', and 'Desktop System'.  At that point I would be able to modify the @Daily  Status to only have the -like sections or the else section.

2019-09-26_15-22-41.png


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>