I have a script to extract list from vCenter on VMware Tools status daily as below. But It contains also Servers which was meant for Testing where its servers name contain Server-Name-TEST. How can I exclude it out for all server-name contain "TEST"

$VMswithoutRunningTools = $PoweredOnVMs | Get-View | Where-Object {($_.Guest.ToolsStatus -match "toolsNotInstalled") -or ($_.Guest.ToolsStatus -match "toolsNotRunning")} | Select-Object Name,@{Name="Status";Expression={$_.Guest.ToolsStatus}}
  • You already got selections (Where-Object) just use them to select VMs that don't have a "Test" in their names. E.g. by using -NotLike. – Seth Sep 12 '17 at 6:17
  • if ($VMswithoutRunningTools) { $VMswithoutRunningTools | Where-Object {$_.Name -NotLike 'WLC','PABX'} | ConvertTo-Html | Out-File $outfilepath } – Jerry Yeo Sep 12 '17 at 6:59
  • I make some changes, it is able to reflect 1 varibles but when i try to put another varibles, it do not work anymore. – Jerry Yeo Sep 12 '17 at 7:00
  • If you did change your code, reflect that change in your question please. Comments are really not suitable to post code. It doesn't look like you had a look at how NotLike or Like works. See about_comparison_operators. – Seth Sep 12 '17 at 8:55

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.