只要你有一件合理的事去做,你的生活就会显得特别美好! ------ 博客首页

SCCM Collection 集合获取计算机最后启动时间

获取计算机客户端最后一次启动时间,我们可以通过多种来源获取,如活动目录组 ,而不仅仅是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

 

posted on 2018-03-20 16:14  --Dongjie  阅读(440)  评论(0编辑  收藏  举报