285 lines
15 KiB
PowerShell
285 lines
15 KiB
PowerShell
|
|
#CONST
|
|||
|
|
$SITENAME="100"
|
|||
|
|
$SCCMSERVER="shscm01.int.samhealth.net"
|
|||
|
|
$SCCMNAMESPACE="root\sms\site_100"
|
|||
|
|
|
|||
|
|
Function Get-SCCMQueryBlock {
|
|||
|
|
param (
|
|||
|
|
[string]$comp,
|
|||
|
|
[int]$NumberofComputers,
|
|||
|
|
[int]$PCID
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
if(!(Test-Connection -ComputerName $comp -Count 1)){
|
|||
|
|
|
|||
|
|
$compStatus = "Offline"
|
|||
|
|
}
|
|||
|
|
else{
|
|||
|
|
$compStatus = "Online"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(get-module -ListAvailable -Name 'ActiveDirectory'){
|
|||
|
|
try { $adTest = ((Get-ADComputer $comp).DistinguishedName -match "Disabled Computers") } catch { $adTest = $true }
|
|||
|
|
if($adTest){
|
|||
|
|
$compStatus += " (disabled or off the domain)"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$i = 0
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Last Hardware Scan" $NumberofComputers $PCID
|
|||
|
|
#Last Hardware Scan
|
|||
|
|
$FindLastHardwareScanQuery = "select SMS_G_System_WORKSTATION_STATUS.LastHardwareScan from SMS_R_System inner join SMS_G_System_WORKSTATION_STATUS on SMS_G_System_WORKSTATION_STATUS.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
|
|||
|
|
$FindLastHardwareScanSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindLastHardwareScanQuery | Select-Object -ExpandProperty LastHardwareScan
|
|||
|
|
|
|||
|
|
if($null -eq $FindLastHardwareScanSCCM){
|
|||
|
|
return $null
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$Year = $FindLastHardwareScanSCCM.substring(0,4)
|
|||
|
|
$Month = $FindLastHardwareScanSCCM.substring(4,2)
|
|||
|
|
$Day = $FindLastHardwareScanSCCM.substring(6,2)
|
|||
|
|
|
|||
|
|
$Hour = $FindLastHardwareScanSCCM.substring(8,2)
|
|||
|
|
$Minute = $FindLastHardwareScanSCCM.substring(10,2)
|
|||
|
|
$Second = $FindLastHardwareScanSCCM.substring(12,2)
|
|||
|
|
|
|||
|
|
$FindLastHardwareScanSCCM = "$Month/$Day/$Year $Hour" + ":" + "$Minute" + ":" + "$Second"
|
|||
|
|
#End Last Hardware Scan
|
|||
|
|
|
|||
|
|
if(!$FindLastHardwareScanSCCM){
|
|||
|
|
$props = [Ordered]@{
|
|||
|
|
Hostname = "$comp"
|
|||
|
|
Status = "$compStatus"
|
|||
|
|
'Current User' = $null
|
|||
|
|
'Last User(s)' = $null
|
|||
|
|
'IP | MAC' = $null
|
|||
|
|
Model = $null
|
|||
|
|
'OS' = $null
|
|||
|
|
'OS Build' = $null
|
|||
|
|
'BIOS Ver' = $null
|
|||
|
|
Encryption = $null
|
|||
|
|
'Free Space' = $null
|
|||
|
|
RAM = $null
|
|||
|
|
'SSO Client' = $null
|
|||
|
|
'Kiosk Role' = $null
|
|||
|
|
'Asset Tag' = $null
|
|||
|
|
'Service Tag' = $null
|
|||
|
|
'Last Reboot' = $null
|
|||
|
|
Printers = $null
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$obj = New-Object -TypeName PSObject -Property $props
|
|||
|
|
|
|||
|
|
return $obj
|
|||
|
|
}
|
|||
|
|
$i++ | ProgressBar $i $comp "Last User SCCM" $NumberofComputers $PCID
|
|||
|
|
$SCCMLastUserLogOnQuery = "select SMS_R_System.LastLogonUserName from SMS_R_System where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$LastUserSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $SCCMLastUserLogOnQuery |
|
|||
|
|
Select-Object -ExpandProperty LastLogonUserName
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM IP Query" $NumberofComputers $PCID
|
|||
|
|
$FindIPQuery = "select SMS_R_System.IPAddresses from SMS_R_System where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindIPSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindIPQuery |
|
|||
|
|
Select-Object -ExpandProperty IPAddresses
|
|||
|
|
if($FindIPSCCM.Count -gt 1){
|
|||
|
|
$FindIPSCCM = $FindIPSCCM[0]
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "Find Model SCCM" $NumberofComputers $PCID
|
|||
|
|
$FindModelQuery = "select SMS_G_System_COMPUTER_SYSTEM.Model from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on
|
|||
|
|
SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$CompModelSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindModelQuery |
|
|||
|
|
Select-Object -ExpandProperty Model
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Bios Version" $NumberofComputers $PCID
|
|||
|
|
$FindBiosVerQuery = "select SMS_G_System_PC_BIOS.SMBIOSBIOSVersion from SMS_R_System inner join SMS_G_System_PC_BIOS on
|
|||
|
|
SMS_G_System_PC_BIOS.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindBiosVerSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindBiosVerQuery |
|
|||
|
|
Select-Object -ExpandProperty SMBIOSBIOSVersion
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM HDD/SSD Space" $NumberofComputers $PCID
|
|||
|
|
$FindFreeSpaceQuery = "select SMS_G_System_LOGICAL_DISK.Size from SMS_R_System inner join SMS_G_System_LOGICAL_DISK on
|
|||
|
|
SMS_G_System_LOGICAL_DISK.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$CompFreeSpaceSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindFreeSpaceQuery |
|
|||
|
|
Select-Object -ExpandProperty Size
|
|||
|
|
$CompFreeSpaceSCCMGB = [math]::Round(($CompFreeSpaceSCCM / 1000), 2)
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM RAM" $NumberofComputers $PCID
|
|||
|
|
$FindMemoryQuery = "select SMS_G_System_X86_PC_MEMORY.TotalPhysicalMemory from SMS_R_System inner join SMS_G_System_X86_PC_MEMORY on
|
|||
|
|
SMS_G_System_X86_PC_MEMORY.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindMemorySCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindMemoryQuery |
|
|||
|
|
Select-Object -ExpandProperty TotalPhysicalMemory
|
|||
|
|
$FindMemorySCCMGB = [math]::Round($FindMemorySCCM / 1MB)
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Asset Tag" $NumberofComputers $PCID
|
|||
|
|
$FindAssetTagQuery = "select SMS_G_System_SYSTEM_ENCLOSURE.SMBIOSAssetTag from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on
|
|||
|
|
SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'"
|
|||
|
|
$FindAssetTagSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindAssetTagQuery |
|
|||
|
|
Select-Object -ExpandProperty SMBIOSAssetTag
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Service Tag" $NumberofComputers $PCID
|
|||
|
|
$FindServiceTagQuery = "select SMS_G_System_SYSTEM_ENCLOSURE.SerialNumber from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on
|
|||
|
|
SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindServiceTagSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindServiceTagQuery |
|
|||
|
|
Select-Object -ExpandProperty SerialNumber
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM OS Name" $NumberofComputers $PCID
|
|||
|
|
$FindOSNameQuery = "select SMS_G_System_OPERATING_SYSTEM.Caption, SMS_G_System_OPERATING_SYSTEM.OSArchitecture, SMS_G_System_OPERATING_SYSTEM.BuildNumber from
|
|||
|
|
SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID =
|
|||
|
|
SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindOSNameSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindOSNameQuery |
|
|||
|
|
Select-Object -ExpandProperty Caption
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM OS Architecture" $NumberofComputers $PCID
|
|||
|
|
$FindOSNameQuery = "select SMS_G_System_OPERATING_SYSTEM.Caption, SMS_G_System_OPERATING_SYSTEM.OSArchitecture, SMS_G_System_OPERATING_SYSTEM.BuildNumber from
|
|||
|
|
SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID =
|
|||
|
|
SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindOSArchSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindOSNameQuery |
|
|||
|
|
Select-Object -ExpandProperty OSArchitecture
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM OS Build" $NumberofComputers $PCID
|
|||
|
|
$FindOSNameQuery = "select SMS_G_System_OPERATING_SYSTEM.Caption, SMS_G_System_OPERATING_SYSTEM.OSArchitecture, SMS_G_System_OPERATING_SYSTEM.BuildNumber from
|
|||
|
|
SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID =
|
|||
|
|
SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindOSBuild = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindOSNameQuery |
|
|||
|
|
Select-Object -ExpandProperty BuildNumber
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Encryption" $NumberofComputers $PCID
|
|||
|
|
$FindEncryptionQuery = "select SMS_G_System_ENCRYPTABLE_VOLUME.ProtectionStatus from SMS_R_System inner join SMS_G_System_ENCRYPTABLE_VOLUME on
|
|||
|
|
SMS_G_System_ENCRYPTABLE_VOLUME.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindEncryptionSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindEncryptionQuery |
|
|||
|
|
Select-Object -ExpandProperty ProtectionStatus
|
|||
|
|
Switch($FindEncryptionSCCM){
|
|||
|
|
0{$FindEncryptionSCCM = "BitLocker (Disabled)"}
|
|||
|
|
1{$FindEncryptionSCCM = "BitLocker (Enabled [Unlocked])"}
|
|||
|
|
2{$FindEncryptionSCCM = "BitLocker (Enabled [Locked])"}
|
|||
|
|
Default{$FindEncryptionSCCM = "Encryption Not Found"}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Last Boot Up Time" $NumberofComputers $PCID
|
|||
|
|
$FindLastBootUpTimeSCCM = Get-SCCMLastBootUpTime $comp
|
|||
|
|
$FindLastBootUpTimeQuery = "select SMS_G_System_OPERATING_SYSTEM.LastBootUpTime from SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on
|
|||
|
|
SMS_G_System_OPERATING_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
|
|||
|
|
$FindLastBootUpTimeSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindLastBootUpTimeQuery |
|
|||
|
|
Select-Object -ExpandProperty LastBootUpTime
|
|||
|
|
if($null -ne $FindLastBootUpTimeSCCM){
|
|||
|
|
$Year = $FindLastBootUpTimeSCCM.substring(0,4)
|
|||
|
|
$Month = $FindLastBootUpTimeSCCM.substring(4,2)
|
|||
|
|
$Day = $FindLastBootUpTimeSCCM.substring(6,2)
|
|||
|
|
$Hour = $FindLastBootUpTimeSCCM.substring(8,2)
|
|||
|
|
$Minute = $FindLastBootUpTimeSCCM.substring(10,2)
|
|||
|
|
$Second = $FindLastBootUpTimeSCCM.substring(12,2)
|
|||
|
|
$FindLastBootUpTimeSCCM = "$Month/$Day/$Year $Hour" + ":" + "$Minute" + ":" + "$Second"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Printers" $NumberofComputers $PCID
|
|||
|
|
$FindPCPrinterQuery = "select SMS_G_System_PRINTER_DEVICE.Name, SMS_G_System_PRINTER_DEVICE.PortName from SMS_R_System inner join SMS_G_System_PRINTER_DEVICE
|
|||
|
|
on SMS_G_System_PRINTER_DEVICE.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
|
|||
|
|
$FindPCPrinterSCCM = (Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindPCPrinterQuery |
|
|||
|
|
Where-Object -Property PortName -ne nul: |
|
|||
|
|
Where-Object -Property PortName -ne PORTPROMPT: |
|
|||
|
|
Where-Object -Property PortName -ne SHRFAX: | Select-Object -ExpandProperty Name) -join ' || '
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM MACAddress" $NumberofComputers $PCID
|
|||
|
|
$FindMACAddressSCCM = Get-SCCMFindMACAddress $comp
|
|||
|
|
|
|||
|
|
$i++ | ProgressBar $i $comp "SCCM Chassis Type" $NumberofComputers $PCID
|
|||
|
|
$FindProcessorQuery = "select SMS_G_System_PROCESSOR.Name from SMS_R_System inner join SMS_G_System_PROCESSOR on SMS_G_System_PROCESSOR.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on
|
|||
|
|
SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'"
|
|||
|
|
$FindProcessorSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindProcessorQuery | Select-Object -ExpandProperty Name
|
|||
|
|
$Model = Get-SCCMFindModelQuery $ComputerName
|
|||
|
|
$FindChassisTypeSCCM = Switch -Wildcard($Model){
|
|||
|
|
"Optiplex*" {
|
|||
|
|
Switch -Wildcard($FindProcessorSCCM){
|
|||
|
|
"Intel(R) Core(TM) i5-9500 CPU*" {"SFF"} #5070
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-6500 CPU*" {"SFF"} #7040
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-6500T*" {"Micro"} #7040
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i7-6700 CPU*" {"SFF"} #7040
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i7-6700T*" {"Micro"} #7040
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-9500T*" {"Micro"} #5070
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-8500 CPU*" {"SFF"} #5060
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-8500T*" {"Micro"} #5060
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-7500*" {"SFF"} #5050
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-4670 CPU*" {"SFF"} #9020
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-4590 CPU*" {"SFF"} #9020
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-4590T CPU*" {"Micro"} #9020M
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-4690 CPU*" {"SFF"} #9020
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-3550 CPU*" {"SFF"} #9010
|
|||
|
|
|
|||
|
|
"Intel(R) Core(TM) i5-2400 CPU*" {"SFF"} #990
|
|||
|
|
|
|||
|
|
Default {"Optiplex - Chassis Type - Unknown"}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
"Latitude*" {"Laptop"}
|
|||
|
|
"Precision*"{"Laptop"}
|
|||
|
|
"M24*" {"Anesthesia Cart"}
|
|||
|
|
"Medix*"{"Anesthesia Cart"}
|
|||
|
|
|
|||
|
|
Default {"Unknown Model/Chassis"}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if($FindAssetTagSCCM -is [array]){
|
|||
|
|
Write-Warning "Dupe record in SCCM - $comp"
|
|||
|
|
$FindAssetTagSCCM = $FindAssetTagSCCM[0]
|
|||
|
|
<#Get-CMDBFallback $comp#>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
<#$cmdbData = Get-CMDBData $comp $FindAssetTagSCCM
|
|||
|
|
$MDBLcmdblocation = Get-Cocation $cmdbData
|
|||
|
|
#>
|
|||
|
|
|
|||
|
|
if($FindLastHardwareScanSCCM){
|
|||
|
|
Write-Host "`n`nPulling cached SCCM data for $comp." -ForegroundColor Yellow
|
|||
|
|
Write-Host "Last Hardware Scan Time: $FindLastHardwareScanSCCM" -ForegroundColor Yellow
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
$props = [Ordered]@{
|
|||
|
|
Hostname = "$comp"
|
|||
|
|
Status = "$compStatus"
|
|||
|
|
'Current User' = "Not Available"
|
|||
|
|
'Last User(s)' = "$LastUserSCCM"
|
|||
|
|
'IP | MAC' = "$FindIPSCCM | $FindMACAddressSCCM"
|
|||
|
|
Model = "$CompModelSCCM ($FindChassisTypeSCCM)"
|
|||
|
|
'OS' = "$FindOSNameSCCM" + " ($FindOSArchSCCM)"
|
|||
|
|
'OS Build' = "Build #$FindOSBuild"
|
|||
|
|
'BIOS Ver' = "$FindBiosVerSCCM"
|
|||
|
|
Encryption = "$FindEncryptionSCCM"
|
|||
|
|
'Free Space' = "$CompFreeSpaceSCCMGB" + " GB"
|
|||
|
|
RAM = "$FindMemorySCCMGB" + " GB "
|
|||
|
|
'SSO Client' = "Not Available"
|
|||
|
|
'Kiosk Role' = "Not Available"
|
|||
|
|
'Asset Tag' = "$FindAssetTagSCCM"
|
|||
|
|
'Service Tag' = "$FindServiceTagSCCM"
|
|||
|
|
'Last Reboot' = "$FindLastBootUpTimeSCCM"
|
|||
|
|
Printers = "$FindPCPrinterSCCM"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$obj = New-Object -TypeName PSObject -Property $props
|
|||
|
|
<#if($cmdbData.values.ConfigurationItem._SHSDELAsset -eq 'True'){
|
|||
|
|
$delInfo = Get-CMDBDELInfo $cmdbData
|
|||
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $delInfo.Owner
|
|||
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Vendor PC' -Value $delInfo.Vendor
|
|||
|
|
$obj | Add-Member -MemberType NoteProperty -Name 'DEL Description' -Value $delInfo.Description
|
|||
|
|
} #>
|
|||
|
|
return $obj
|
|||
|
|
}
|