The error for the 81 characters is the one I am interested in. Why am I allowed to create services with long names (apparently it should be possible up to 256 characters according to this), if somewhere down the line a smaller value is checked to determine continuing with starting services?
Couldn't find a confirmed bug about this anywhere or documentation in PowerShell that those commands don't work with "too long" service names. So why is this happening? Where should I report a bug about this?
P.S. the script colouring did now show me that with the start commands error feedback, the 81 string wasn't put between single quotes. Might that help to pinpoint what is going wrong?
It's probably limited to 80 characters so that it fits on an IBM punched card.
Sorry, I digress. I was able to recreate the problem with PS 5.1 on Win10. It could be fixed in PS 7, I don't have that installed anywhere to test with. I see that Remove-Service was added in PS 6.0, so maybe other changes were made.
I'll speculate that the developers might have wondered "why would anyone define a service with with a really long name when the DisplayName would seem to be the better place for a verbose value?".
Looks like net.exe can start the service or you can use a shorter name and use DisplayName for the longer text.
$Name80 = "TestingLengthOfServiceNameWith--------------------------------------80characters"
$Name81 = "TestingLengthOfServiceNameWith---------------------------------------81characters"
$Name80.Length
$Name81.Length
New-Service -Name $Name80 -BinaryPathName %windir%\system32\svchost.exe
New-Service -Name $Name81 -BinaryPathName %windir%\system32\svchost.exe
"Start 80"
Get-Service -Name $Name80 | Start-Service
"Start 81"
Get-Service -Name $Name81 | Start-Service
"Net 80"
net.exe start $Name80
"Net 81"
net.exe start $Name81
"Try generic"
Get-Service -Name "testing*" | Start-Service
"Can we query them? "
sc.exe qc $Name80
sc.exe qc $Name81
"Now delete them"
sc.exe delete $Name80
sc.exe delete $Name81
Or use display name.
$Name80 = "Testing80"
$Name81 = "Testing81"
$DName80 = "TestingLengthOfServiceNameWith--------------------------------------80characters"
$DName81 = "TestingLengthOfServiceNameWith---------------------------------------81characters"
New-Service -Name $Name80 -DisplayName $DName80 -BinaryPathName %windir%\system32\svchost.exe
New-Service -Name $Name81 -DisplayName $DName81 -BinaryPathName %windir%\system32\svchost.exe
"Start 80"
Get-Service -Name $Name80 | Start-Service
Get-Service -DisplayName $DName80 | Start-Service
"Start 81"
Get-Service -Name $Name81 | Start-Service
Get-Service -DisplayName $DName81 | Start-Service
"Net 80"
net.exe start $Name80
"Net 81"
net.exe start $Name81
"Try generic"
Get-Service -Name "testing*" | Start-Service
"Can we query them? "
sc.exe qc $Name80
sc.exe qc $Name81
"Now delete them"
sc.exe delete $Name80
sc.exe delete $Name81
Thanks @MotoX80 !
Seems then like an oversight to have added backwards compatibility support for 80 characters in one place but not verify that on creation of the service.
Regardless, I read your comment that they fixed it in PS 7.2.6 so will try that out.
Having used PS 5 by default, I checked the LTS and don't see PS5 mentioned there, so guessing that is indeed not receiving fixes. I'm a bit confused though that no longer supported, PS5 does not get upgraded to PS7 and you have to install it manually/separately... Seems a bit odd to have that as the default PS if it is no longer supported. Anyway, the fact that it should be fixed now let me to conclude that this was in fact undesired behaviour.