top of page
Yazarın fotoğrafıS.Ergül

Checked Client from AD via last logon date

Güncelleme tarihi: 16 Ara 2020

Hi Folks,


Today, we will checked our sccm client according to their lastest login date on AD. You can use below script to check that but ıf you want to check 2 different domain, both of them be trusted.


##########################################################
#Script Title: Get Sccm no client last logon date 
#Author: Selcuk ERGUL
#Date Created: 11/27/2017
#Version: V1.0 - First relase by Dursun ALACAM
#		  V2.0 - Check 2 different domains added by Selcuk ERGUL
#Description: Check clients on AD according to lastest logon date.
##########################################################

# Import the ActiveDirectory module to enable the Get-ADComputer CmdLet
Import-Module ActiveDirectory

$CurrentDir= split-path -parent $MyInvocation.MyCommand.Definition
$gun = "-30"
$gun = -30 # How many days ago, client was not logon.

$Dates=[DateTime] $(get-date -format "MM/dd/yyyy  H:mm:ss tt").tostring()
$ax="ComputerName;Ip;Enabled;LastLogonDate;Expire Days;DistinguishedName`r`n"

#####Enter Domains Name ###########
$DSName1 = "domain name 1"
$DSName2 = "domain name2"

Import-Csv $CurrentDir\no-computers.csv -Delimiter ";" |
ForEach-Object {
	$ComputerName=$_.ComputerName

	if ((Get-ADComputer -server $DSName1 -Filter "Name -like '$ComputerName'" -Properties LastLogonDate,IPv4Address).name -eq $ComputerName) #SCCM client domainde varsa
		{
			$AdComputer = Get-ADComputer -server $DSName1 -Filter "Name -like '$ComputerName'" -Properties LastLogonDate,IPv4Address
			$adlstfilter=[math]::Round(($DateS-$AdComputer.LastLogonDate).TotalDays)
			$adlastlogon=$AdComputer.lastlogonDATE
			$adenabled=$AdComputer.enabled
			$ip=$AdComputer.IPv4Address
			$adDistinguishedName=$AdComputer.DistinguishedName -replace '[,]',' '
			$ax+="$ComputerName;$ip;$adenabled;$adlastlogon;$adlstfilter;$adDistinguishedName`r`n"
		}
	elseif((Get-ADComputer -server $DSName2 -Filter "Name -like '$ComputerName'" -Properties LastLogonDate,IPv4Address).name -eq $ComputerName)
	{
			$AdComputer = Get-ADComputer -server $DSName2 -Filter "Name -like '$ComputerName'" -Properties LastLogonDate,IPv4Address
			$adlstfilter=[math]::Round(($DateS-$AdComputer.LastLogonDate).TotalDays)
			$adlastlogon=$AdComputer.lastlogonDATE
			$adenabled=$AdComputer.enabled
			$ip=$AdComputer.IPv4Address
			$adDistinguishedName=$AdComputer.DistinguishedName -replace '[,]',' '
			$ax+="$ComputerName;$ip;$adenabled;$adlastlogon;$adlstfilter;$adDistinguishedName`r`n"
	}
	else
		{
			$ax+="$ComputerName;;;;Domainde Yok;`r`n"
		}
}
out-file -filepath "$CurrentDir\$gun No computer $(Get-Date -Format dd-MMMMMMMMMMMMM-yyyy).csv" -InputObject $ax -encoding UTF8
write-host "$ax"
write-host $AdComputers.count $noclients.count


28 görüntüleme0 yorum

Son Yazılar

Hepsini Gör

Comments


Post: Blog2_Post
bottom of page