Error: You must provide a value expression on the right-hand side of the '-' ope

I am getting error: You must provide a value expression on the right-hand side of the ‘-’ operator when I am trying to execute following lines of code in PS:
$list = gc .\files_to_delete.txt
Get-SmbShare | ?{$_.name -in $list} | Remove-SmbShare -Force

Can somebody help me out, the code runs fine in PS version 5.1 but it gives error in Windows server 2003 PS version 2.0

whats there in $list, seems like its empty or the file has empty lines.

diveshishere32,

Any specific reason you are running this through Get-SMBShare and pulling all SMB Shares? Instead would this not work?

I would advise to use a full path as well when building scripts. This will help to alleviate any issues if PowerShell is not in the correct file path.

Remove-SMBShare -Name (Get-Content .\Files_To_Delete.txt)

Remove-SMBShare -Name (Get-Content C:\Temp\Files_To_Delete.txt)

I was working on a really clever response, but then I re-read the last line of your post… Do you even have the Get-SmbShare cmdlet in Server 2003? From what I can find, that came out in Server 2012 which was Powershell 3.0, right?

The old version of Posh is my first guess…

Charles,

Good catch, you are correct. Get-SMBShare & Remove-SMBShare are not available until Windows Server 2012 which users PowerShell 3.0. With Window Server 2003 only PowerShell 2.0 was ever supported for its installation.