0

The most popular answer for this question involves the following Windows powershell code:

$file1 = Get-Content C:\temp\file1.txt  
$file2 = Get-Content C:\temp\file2.txt   
$Diff = Compare-Object $File1 $File2  
$LeftSide = ($Diff | Where-Object $_.SideIndicator -eq '<=').InputObject  
$LeftSide | Set-Content C:\temp\file3.txt

Yet when I try to use that code, I get the following error:

Where-Object : Cannot bind argument to parameter 'FilterScript' because it is null.

Why am I getting this error, and how do I resolve it?

1 Answer 1

4

Looks like a simple syntax error. Where-Object requires the conditional filter to be presented as a scriptblock (hence "FilterScript"):

Where-Object {$_.SideIndicator -eq '<='}
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you! That fixed the bug. Now, the bigger question... why doesn't it work? Always getting a 0 byte output file.
I'd check $Diff and make sure you're actually getting LH side differences from your Compare-Object.
Do you have time to discuss this in chat?
Not right now (I have burgers on the grill), but if you're having problems with the Compare-Object results, just post another question and somebody will probably chime in.
Thank you. Toss one on the grill for me too! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.