-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGet-SCCMADDevices.ps1
More file actions
42 lines (34 loc) · 1.51 KB
/
Get-SCCMADDevices.ps1
File metadata and controls
42 lines (34 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$CMSite = Get-PSProvider -PSProvider CMSITE
Set-Location -Path "$($CMSite.Drives.Name):\"
#Currently quering All Systems Collection.
$InActiveClients = Get-CMCollectionMember -CollectionName 'All Systems'
$ProcessedObjects = @()
foreach($Client in $InActiveClients){
$Client.Name
Try{
$ADComputerInfo = Get-ADComputer -Identity $Client.Name -Properties LastLogonDate,OperatingSystem -ErrorAction STOP
$Properties = {
[Ordered]@{
Name = $Client.Name
OS = $ADComputerInfo.OperatingSystem
Enabled = $ADComputerInfo.Enabled
LastLogonDate = $ADComputerInfo.LastLogonDate
LastLogonDateInDays = if(!([System.string]::IsNullOrEmpty($ADComputerInfo.LastLogonDate))){(New-TimeSpan -Start $ADComputerInfo.LastLogonDate -End (Get-Date)).days}Else{"N/A"}
LastPolicyRequest = $Client.LastPolicyRequest
}}
}
Catch{
$Properties = {
[Ordered]@{
Name = $Client.Name
OS = 'N/A'
Enabled = 'N/A'
LastLogonDate = 'N/A'
LastLogonDateInDays = 'N/A'
LastPolicyRequest = 'N/A'
} }
}
$ProcessedObjects += New-Object -TypeName PSObject -Property (&$Properties)
}
$ProcessedObjects | Export-Csv -Path E:\Scripts\LOGS\CMInActiveClients.csv -NoTypeInformation -Delimiter ';'