Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PSService] Single -setup parameter not working for powershell v2 #22

Open
cloverhap opened this issue Mar 14, 2019 · 3 comments
Open

Comments

@cloverhap
Copy link

I was testing the (mostly) unmodified service script on a machine with powershell v2 installed as we have some in our environment, and came across this message:

Parameter set cannog be resolved using the specified named parameters.
At line:1 char:32

  • services\PSService.ps1 <<<< -setup
    • CategoryInfo : InvalidArgument: (:) [PSService.ps1], P
      arameterBindingException
    • FullyQualifiedErrorId : AmbiguousParameterSet,PSService.ps1

I removed line 233 (below) to make it work since I won't be using the 'Setup' parameter set, but i'm wondering if this is happening on other users as well?

[Parameter(ParameterSetName='Setup', Mandatory=$true)] <<<
[Parameter(ParameterSetName='Setup2', Mandatory=$true)]
[Switch]$Setup, # Install the service

@cbm-afettach
Copy link

Hello @cloverhap. I had the same issue and commenting the line 233 resolved it. Thanks

@JFLarvoire
Copy link
Owner

Hello,

What exact OS and PS versions do you have?
Because on the only system I have with PS v2, a Windows 2008 R2 server, it works just fine:

PS C:\Users\Administrator> $psversiontable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.8806
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1


PS C:\Users\Administrator> psservice.ps1 -?

NAME
C:\Tools\PSService.ps1

SYNOPSIS
A sample Windows service, in a standalone PowerShell script.


SYNTAX
C:\Tools\PSService.ps1 [-Status] [<CommonParameters>]

C:\Tools\PSService.ps1 -Start [<CommonParameters>]

C:\Tools\PSService.ps1 -Stop [<CommonParameters>]

C:\Tools\PSService.ps1 -Restart [<CommonParameters>]

C:\Tools\PSService.ps1 -Setup [-Credential <PSCredential>] [<CommonParameters>]

C:\Tools\PSService.ps1 -Setup -UserName <String> [-Password <String>] [<CommonParameters>]

C:\Tools\PSService.ps1 -Remove [<CommonParameters>]

C:\Tools\PSService.ps1 -Service [<CommonParameters>]

C:\Tools\PSService.ps1 -SCMStart [<CommonParameters>]

C:\Tools\PSService.ps1 -SCMStop [<CommonParameters>]

C:\Tools\PSService.ps1 -Control <String> [<CommonParameters>]

C:\Tools\PSService.ps1 -Version [<CommonParameters>]


DESCRIPTION
This script demonstrates how to write a Windows service in pure PowerShell.
It dynamically generates a small PSService.exe wrapper, that in turn
invokes this PowerShell script again for its start and stop events.


RELATED LINKS

REMARKS
To see the examples, type: "get-help C:\Tools\PSService.ps1 -examples".
For more information, type: "get-help C:\Tools\PSService.ps1 -detailed".
For technical information, type: "get-help C:\Tools\PSService.ps1 -full".



PS C:\Users\Administrator>

@cloverhap cloverhap changed the title [PSService] Singe -setup parameter not working for powershell v2 [PSService] Single -setup parameter not working for powershell v2 May 25, 2020
@JFLarvoire
Copy link
Owner

Actually there's a simple workaround. Run:
PSService.ps1 -Setup -UserName LocalSystem
This satisfies PowerShell 2, and does not change the User Name as LocalSystem is the default user name that would be used anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants