why is this incorrect?

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

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

 
Participant
1 week, 5 days ago.

  • Author
    Posts
  • #181722

    Participant
    Topics: 3
    Replies: 6
    Points: 16
    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: 3
    Replies: 6
    Points: 16
    Rank: Member

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

  • #181749

    Participant
    Topics: 3
    Replies: 66
    Points: 336
    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: 3
    Replies: 6
    Points: 16
    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

    Participant
    Topics: 3
    Replies: 66
    Points: 336
    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

You must be logged in to reply to this topic.