Chevello Lo
Chevello Lo

Reputation: 23

Powershell Out-File show only if filled

I'm trying to output files to a .txt, but I only want to see the attributes which are filled. Some help would be greatly appreciated.

$T | ft Name,Logonworkstations | OUT-FILE c:\temp\name.txt

Upvotes: 1

Views: 577

Answers (1)

Richard
Richard

Reputation: 7000

$T | ?{[string]::IsNullOrWhiteSpace($_.Name) -ne $ture -and `
       [string]::IsNullOrWhiteSpace($_.Logonworkstations) -ne $true} `
   | ft Name,Logonworkstations | OUT-FILE c:\temp\name.txt

This will check if ether Logonworkstations or Name attributes have a $null or and empty string ("") as there value. If ether of them are null/empty the line is skipped. But if both attributes has a value the object will be write to file.

Upvotes: 2

Related Questions