why is this incorrect?

Welcome Forums General PowerShell Q&A why is this incorrect?

Viewing 4 reply threads
  • Author
    Posts
    • #181722
      Participant
      Topics: 4
      Replies: 6
      Points: 27
      Rank: Member

      PS C:\WINDOWS\system32> Get-Service -ServiceName 'bits
      >> '

      Get-Service : Cannot find any service with service name 'bits
      '.
      At line:1 char:1
      + Get-Service -ServiceName 'bits
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (bits
      :String) [Get-Service], ServiceCommandException
      + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

    • #181731
      Participant
      Topics: 4
      Replies: 6
      Points: 27
      Rank: Member

      any help please in letting me understand why the powershell extended mode doesnt treat the ' closing in the next line?

    • #181749
      Moderator
      Topics: 3
      Replies: 85
      Points: 453
      Helping Hand
      Rank: Contributor

      It looks like PowerShell is accepting the closing ', but it is also including the return character in the -ServiceName string. Because you are using single quotes, it is taking all of your input literally, so it is searching for a service name that looks like "bits
      "
      or

      bits[return]
    • #181755
      Participant
      Topics: 4
      Replies: 6
      Points: 27
      Rank: Member

      It looks like PowerShell is accepting the closing ', but it is also including the return character in the -ServiceName string. Because you are using single quotes, it is taking all of your input literally, so it is searching for a service name that looks like "bits

      "

      or

      1
      bits[return]
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Thats correct, but double quotes doesnt work either. It is taking the carriage return value as well along with the closing quotes. Is this extensible shell designed to work only for strings and not for running command let syntax as above?

    • #181761
      Moderator
      Topics: 3
      Replies: 85
      Points: 453
      Helping Hand
      Rank: Contributor

      I think this will solve your problem: https://devblogs.microsoft.com/scripting/powertip-line-continuation-in-powershell/

      *Edit: Actually I think that won't work. It seems that you can split a command across multiple lines, but you can't split strings across multiple lines without including the return character between lines: https://stackoverflow.com/questions/3235850/how-to-enter-a-multi-line-command

Viewing 4 reply threads
  • The topic ‘why is this incorrect?’ is closed to new replies.