Logon script executing Get-Service command returns services name == display name

Hello there,

I have a logon script written in PowerShell that executes the Get-Service command (this is the full, unaltered source-code of the script).

$ErrorActionPreference="Continue"
$VerbosePreference="Continue"
$date=Get-Date -Format "yyyyMMddHHmmss"

$Path="C:\@Softs\ScriptDeployment"
$LogPath="$Path\Logs"
$LogFile="$LogPath\LogonScript-$date.txt"

try { Start-Transcript $LogFile } catch { Start-Transcript $LogFile -Force }

cd C:\@Softs\Template

Get-Service

Stop-Transcript

However, the result of the command shows all the services with the same name and display name (this is copy-pasted directly from the transcript file) :

Status   Name               DisplayName
------   ----               -----------
Running  AdobeARMservice    AdobeARMservice
Stopped  AJRouter           AJRouter
Stopped  ALG                ALG
Stopped  AppIDSvc           AppIDSvc
Stopped  Appinfo            Appinfo
[...]

I just don’t understand why. If I execute the Get-Service command in a PowerShell prompt directly on the machine, I get the expected result (i.e. services names and display names are different).

I am at a loss, and so are ChatGPT and Copilot. And I cannot find anything about that exact issue through Google searches.

Any help is appreciated.

Thanks :slight_smile:

Just to confirm, the transcript file is the output you copied where the name and displayname are the same?

If so, I’m not able to reproduce. I used basically the same code you shared and the transcript file looks normal

Status   Name               DisplayName
------   ----               -----------
Running  AdobeARMservice    Adobe Acrobat Update Service
Running  AdobeUpdateService AdobeUpdateService

can you confirm where you are seeing that? I ran the code ad-hoc not as a login script but I’d think it’d be no different. Is this all the code? you’re not manipulating it and outputting it in another fashion? This isn’t a seperate log file where someone is doing custom output?

And I did the same with the same results as @dotnVo. One can only suspect it has to do with being run as a login script ??

I have edited my post to answer your questions, but in short yes I have provided the full, unaltered source-code of the script and the service table is copy-pasted directly from the transcript file (except the […] part at the end, which I have added).

I just tested your code exactly as it is and I cannot reproduce the behaviour you’re stating. :man_shrugging:t3:

Since you basically just have the list of services in your transcript, have you tried piping the output to Out-File instead?

Regardless of that: What’s the actual purpose of that script? Whatfor do you need this list and why are you changing the directory in it?