首页 > 技术文章 > SCCM Collection 集合获取计算机最后启动时间

Aldj 2018-03-20 16:14 原文

获取计算机客户端最后一次启动时间,我们可以通过多种来源获取,如活动目录组 ,而不仅仅是SCCM 收集,希望对您有所帮助,下面分享PowerShell 脚本

# 1

$CollectionName = 'CollectionName'

$file = "Csv report file path"

$SiteServer = 'SCCMSERVER'

$SiteCode = 'YourSCCMSiteCode'

#Get the collection using WMI

$Collection = get-wmiobject -ComputerName $siteServer -NameSpace "ROOT\SMS\site_$SiteCode" -Class SMS_Collection | where {$_.Name -eq "$CollectionName"}

#Get the collection members

$CollectionMmebers = Get-WmiObject -ComputerName $SiteServer -Namespace "ROOT\SMS\site_$SiteCode" -Query "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='$($Collection.CollectionID)' order by name" | select Name

#The $CollectionMembers lastBoot

 $data = @() ForEach($Computer in $CollectionMmebers) { try { $operatingSystem = Get-WmiObject Win32_OperatingSystem -ComputerName $($Computer.Name) $lastBoot = [Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime) } catch { $lastBoot = "ERROR Connecting" } $data += New-Object PSObject -Property @{ Name = $Computer.Name "Last Boot" = $lastBoot } } $data | Export-Csv $file

 

推荐阅读