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

Welcome Forums General PowerShell Q&A Why does IP work but not CName for Get-Service?

This topic contains 2 replies, has 3 voices, and was last updated by

4 months, 2 weeks ago.

  • Author
  • #121332

    Points: 286
    Rank: Contributor

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

    Import-CSV .\SSAS_services.csv |
            Get-Service $_.Service -ComputerName $_.Server -PipelineVariable svc|
                Set-Service -Status $_.Task -StartupType $_.'Startup Type' -PassThru
        } |
        Select-Object MachineName, Name, Status, StartType, @{n='OldStatus';e={$svc.Status}}, @{n='OldStartType';e={$svc.StartType}} | 
        tee-object -FilePath '.\ChangeServices_LOG.txt' #-Append

    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...

  • #122930

    Points: 1,140
    Helping Hand
    Rank: Community Hero

    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.

  • #123155

    Points: 743
    Helping Hand
    Rank: Major Contributor

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

The topic ‘Why does IP work but not CName for Get-Service?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort