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.ps1 - Assembly types not supported on Windows Server 2022 #43

Open
marcleblanc2 opened this issue Jan 22, 2025 · 2 comments
Open

Comments

@marcleblanc2
Copy link

marcleblanc2 commented Jan 22, 2025

Hey, thank you for creating the PSService.ps1 script! I'm trying to run the -Setup process and I'm getting this error. I've read the notes in the script, have searched the other issues in the repo, and have Googled it, and haven't found a workaround yet. Is this something you've seen before, or have a workaround for?

Error message:
PSService.ps1: Failed to create the C:\Windows\System32\PSService.exe service stub. Both the assembly types 'ConsoleApplication' and 'WindowsApplication' are not currently supported.

Output of $psversiontable:

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

OS info from System > About
Edition Windows Server 2022 Standard
Version 21H2
Installed on ‎2024-‎02-‎02
OS build 20348.2762

Thank you!

@marcleblanc2
Copy link
Author

marcleblanc2 commented Jan 22, 2025

This issue PowerShell/PowerShell#13344
lead me to MicrosoftDocs/PowerShell-Docs#6499
which lead me to https://answers.microsoft.com/en-us/windowserver/forum/all/powershell-v2-engine-on-windows-server-2k22/68d79b08-32df-45b9-92b4-04d56ca7dd12
which lead me to realize that I can just run an old version of PowerShell as a workaround.

# PS E:\Data> PowerShell -Version 5 .\PSService.ps1 -Verbose -Debug -Setup
# DEBUG: Installation is necessary

# Confirm
# Continue with this operation?
# [Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): A
# VERBOSE: Installing C:\Windows\System32\PSService.ps1
# VERBOSE: Compiling C:\Windows\System32\PSService.exe
# VERBOSE: Registering service PSService
# PS E:\Data> PowerShell -Version 5 .\PSService.ps1 -Verbose -Debug -Status
# Stopped
# PS E:\Data> PowerShell -Version 5 .\PSService.ps1 -Verbose -Debug -Start
# VERBOSE: Starting service PSService
# PS E:\Data> PowerShell -Version 5 .\PSService.ps1 -Verbose -Debug -Stop
# VERBOSE: Stopping service PSService
# PS E:\Data> PowerShell -Version 5 .\PSService.ps1 -Verbose -Debug -Remove
# VERBOSE: Removing service PSService
# VERBOSE: [SC] DeleteService SUCCESS
# VERBOSE: Deleting file C:\Windows\System32\PSService.exe
# VERBOSE: Deleting file C:\Windows\System32\PSService.ps1

This should likely either be fixed or noted.

@JFLarvoire
Copy link
Owner

When I created this script, I had to insert a directive #Requires -version 2 to make it clear that it was not compatible with PowerShell version 1.
Nowadays, this is a non-issue. PS version 1 only ran on Windows XP. And in the very unlikely case that somebody still runs PSService.ps1 on XP, it's possible to upgrade it to PS version 2.

As far as I know, there's nothing in there that prevents PSService.ps1 from running with any subsequent PS version.
The simplest workaround is just to remove that #Requires directive.
I'll investigate to see if there's a way to keep the directive, while expressing that any version >= version 2 will work.

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

2 participants