locked
Powershell Get-ADComputer Help Needed RRS feed

  • Question

  • Hello All,

    I have used Get-ADComputer to do an export of all computers in our environment as I need to install an agent to all servers. It is not quite what I need though. Can someone please help with the following two scenarios:

    1. I need the script to not include decommissioned servers so is it possible to have the command only include computers that have checked in in the past 90 days?

    2. I need to check that I service has been installed on each machine. Is it possible to run a powershell command so that it checks each computer and outputs a list of servers where a particular service name is installed?

    Your help is much appreciated.

    James

    • Moved by Bill_Stewart Friday, November 28, 2014 5:24 PM This is not "scripts on demand"
    Monday, November 3, 2014 9:45 AM

Answers

  • Hi James,

    1. That is easy. Just filter the output by the lastlogondate like this e.g.:
    $days = [DateTime]::Today.AddDays(-90) | Get-ADComputer -filter {lastlogondate -le $days}

    2. You can do that with Get-Service:
    Get-Service -name 'servicename' -computer 'servername'

    Cheers
    Chaib


    Monday, November 3, 2014 11:27 AM

All replies

  • Hi James,

    1. That is easy. Just filter the output by the lastlogondate like this e.g.:
    $days = [DateTime]::Today.AddDays(-90) | Get-ADComputer -filter {lastlogondate -le $days}

    2. You can do that with Get-Service:
    Get-Service -name 'servicename' -computer 'servername'

    Cheers
    Chaib


    Monday, November 3, 2014 11:27 AM
  • All of this is possible but we will not write this for you.

    Start here: http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

     


    ¯\_(ツ)_/¯

    Monday, November 3, 2014 7:08 PM