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

Welcome Forums General PowerShell Q&A Error: You must provide a value expression on the right-hand side of the '-' ope

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
2 weeks, 1 day ago.

  • Author
    Posts
  • #174502

    Participant
    Topics: 1
    Replies: 0
    Points: -9
    Rank: Member

    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

  • #174508

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,438
    Helping Hand
    Rank: Community Hero

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

  • #174601

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    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)
  • #174643

    Participant
    Topics: 6
    Replies: 78
    Points: 143
    Helping Hand
    Rank: Participant

    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...

  • #174670

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    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.

     

You must be logged in to reply to this topic.