获取计算机客户端最后一次启动时间,我们可以通过多种来源获取,如活动目录组 ,而不仅仅是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 "ROOTSMSsite_$SiteCode" -Class SMS_Collection | where {$_.Name -eq "$CollectionName"} #Get the collection members $CollectionMmebers = Get-WmiObject -ComputerName $SiteServer -Namespace "ROOTSMSsite_$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