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

js
 
Participant
1 month ago.

  • Author
    Posts
  • #121332

    Participant
    Points: 90
    Rank: Member

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

    Import-CSV .\SSAS_services.csv |
        ForEach-Object{
            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:

    DCVPIM108 

    IP: 10.101.19.8 

    CName:computer1

    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

    Participant
    Points: 319
    Helping Hand
    Rank: Contributor

    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
    js

    Participant
    Points: 318
    Helping Hand
    Rank: Contributor

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

You must be logged in to reply to this topic.