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

Viewing 4 reply threads
  • 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: 1160
      Points: 4,056
      Helping Hand
      Rank: Community Hero

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

    • #174601
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      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: 108
      Points: 304
      Helping Hand
      Rank: Contributor

      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: 115
      Points: 433
      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.

       

Viewing 4 reply threads
  • The topic ‘Error: You must provide a value expression on the right-hand side of the '-' ope’ is closed to new replies.