Why does IP work but not CName for Get-Service?

I have this script that changes services per a csv file input

<span class="typ">Import</span><span class="pun">-</span><span class="pln">CSV </span><span class="pun">.</span><span class="pln">\SSAS_services</span><span class="pun">.</span><span class="pln">csv </span><span class="pun">|</span>
    <span class="typ">ForEach</span><span class="pun">-</span><span class="typ">Object</span><span class="pun">{</span>
        <span class="typ">Get</span><span class="pun">-</span><span class="typ">Service</span><span class="pln"> $_</span><span class="pun">.</span><span class="typ">Service</span> <span class="pun">-</span><span class="typ">ComputerName</span><span class="pln"> $_</span><span class="pun">.</span><span class="typ">Server</span> <span class="pun">-</span><span class="typ">PipelineVariable</span><span class="pln"> svc</span><span class="pun">|</span>
            <span class="typ">Set</span><span class="pun">-</span><span class="typ">Service</span> <span class="pun">-</span><span class="typ">Status</span><span class="pln"> $_</span><span class="pun">.</span><span class="typ">Task</span> <span class="pun">-</span><span class="typ">StartupType</span><span class="pln"> $_</span><span class="pun">.</span><span class="str">'Startup Type'</span> <span class="pun">-</span><span class="typ">PassThru</span>
    <span class="pun">}</span> <span class="pun">|</span>
    <span class="typ">Select</span><span class="pun">-</span><span class="typ">Object</span> <span class="typ">MachineName</span><span class="pun">,</span> <span class="typ">Name</span><span class="pun">,</span> <span class="typ">Status</span><span class="pun">,</span> <span class="typ">StartType</span><span class="pun">,</span> <span class="pun">@{</span><span class="pln">n</span><span class="pun">=</span><span class="str">'OldStatus'</span><span class="pun">;</span><span class="pln">e</span><span class="pun">={</span><span class="pln">$svc</span><span class="pun">.</span><span class="typ">Status</span><span class="pun">}},</span> <span class="pun">@{</span><span class="pln">n</span><span class="pun">=</span><span class="str">'OldStartType'</span><span class="pun">;</span><span class="pln">e</span><span class="pun">={</span><span class="pln">$svc</span><span class="pun">.</span><span class="typ">StartType</span><span class="pun">}}</span> <span class="pun">|</span><span class="pln"> 
    tee</span><span class="pun">-</span><span class="kwd">object</span> <span class="pun">-</span><span class="typ">FilePath</span> <span class="str">'.\ChangeServices_LOG.txt'</span> <span class="com">#-Append</span>

apparently, the ServiceController manager throws an exception

Cannot open Service Control Manager on computer ‘’. This operation might require other privileges

when i used CName for my server as computer name, but after reading some forums I have tried IP/hostname and it ran fine.

for example, if i have a server:




only DCVPIM108 or the IP address are allowed as part of -ComputerName argument. is there a way to make it accept CNames through the script somehow?


I have read that “You must be an admin on the remote computer and on the local system you must be running elevated. Some services may be protected and cannot be modified.”

but i dont understand what does CName have to do with that? if IP works it means the admin access is granted/elevated…CName is just an alias name for the computer/server, it shouldnt have any effect at all…

There are many characters that have special meaning, use in PowerShell and cannot be used for any other reason. Of course all languages, parsers have such restrictions.

If you tried to ping by cname as you have it specified, ‘CN:computer1’, it would fail as well.

Test-Connection -ComputerName CName:kcd
Ping request could not find host CName:kcd. Please check the name and try again

Test-Connection -ComputerName CName:kcd

Test-NetConnection -ComputerName CName:kcd

You can only use the cname name string not the colon separated approach you are using.

For PSRemoting, with the exception of a hand full of commands, you must be an admin on any remote host you communicate with and several cases must be running PS as admin.

Cname = canonical name = the original name. I think you mean the alias. :slight_smile: Back to your regularly scheduled post.