Find servers that don't have SCCM installed

Welcome Forums General PowerShell Q&A Find servers that don't have SCCM installed

This topic contains 9 replies, has 4 voices, and was last updated by

 
Keymaster
8 months, 3 weeks ago.

  • Author
    Posts
  • #78889
    cm

    Participant
    Points: 0
    Rank: Member

    Hi. I have following script which will determine which servers DO have SCCM installed and currently displays to a window inside of PrimalScript. I only want to show those that don't have it installed.

    Code

  • #78892

    Participant
    Points: 0
    Rank: Member

    You should query if the server is ONLINE first, then if SCCM is installed, something like this:

    if (Test-Connection -CN $Computer -Count 1 -BufferSize 16 -Quiet) {
    
        if (Get-Service -Name 'sms agent host') {
    
            Write-Host "SCCM Agent is installed on " $Server
    
        }
    
        Else {
            
            Write-Host "SCCM Agent is not installed on " $Server
    
        }
    
    }
    

    Note that I haven't tested this code, it might need a little error management but it should work.

    • #78893
      cm

      Participant
      Points: 0
      Rank: Member

      Ivan,

      Thank you. What if I only want servers that don't have it installed to come up?

    • #78899

      Participant
      Points: 9
      Rank: Member

      Just an idea: You can get the server with SCCM client installed from SCCM – there are SCCM cmdlets for this. So you just have to compare the list of servers from the SCCM with the list of servers from AD or any other list you have available. 😉

    • #78902
      cm

      Participant
      Points: 0
      Rank: Member

      Olaf,

      Unfortunately we are on SCCM 2007 and it's in the (long) process of being upgraded to 2012. We do not get to control SCCM even though we host the servers in our datacenter, unfortunately. We do have 2012 R2 Servers in our environment so until they fully get 2012 SCCM up and running...

      .. Also, we have a VBScript that does what I wanted to do, but with Windows 10 rolling around soon in our environment, we needed to move to a current scripting language.

  • #78896

    Participant
    Points: 0
    Rank: Member

    If you want only the servers without SCCM then comment out line 5.

    That's quick and dirty fix.

  • #78916

    Keymaster
    Points: 0
    Team Member
    Rank: Member
    Try {
    
        Get-WmiObject -ComputerName $Computer -Namespace root\CCM -Class SMS_Client -ErrorVariable SMSError
    }
    Catch [System.Exception]{
    
        Write-Output ($Computer + ' returned error ' + $SMSError)
    
    }
  • #78940

    Keymaster
    Points: 0
    Team Member
    Rank: Member

    Now that I'm not rushing to beat a dying laptop battery, I can elaborate. ^_^

    You can use Get-WMIObject and target the SMS_Client class in the root\ccm namespace to check the installation of the client. There's actually a lot of data that you can get out of the class. If the class doesn't exist, the client is either not installed, or horribly broken.

    • #79157
      cm

      Participant
      Points: 0
      Rank: Member

      Hey can you expand further? I tried it out and I got a lot of servers listed I know have SCCM installed.

    • #92498

      Keymaster
      Points: 0
      Team Member
      Rank: Member

      If it returns something of ($Computer + ' returned error ' + $SMSError) in the output, those will be the machines that do not have the agent installed.

The topic ‘Find servers that don't have SCCM installed’ is closed to new replies.