SCCM Query can be jobbed and added ClearCCMCache
This commit is contained in:
parent
f432187f92
commit
d271979205
|
|
@ -12,7 +12,7 @@
|
||||||
RootModule = 'Get-PC.psm1'
|
RootModule = 'Get-PC.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '0.3.15'
|
ModuleVersion = '0.3.16'
|
||||||
|
|
||||||
# Supported PSEditions
|
# Supported PSEditions
|
||||||
# CompatiblePSEditions = @()
|
# CompatiblePSEditions = @()
|
||||||
|
|
|
||||||
|
|
@ -199,11 +199,8 @@ function Get-PCBatchInvoke {
|
||||||
Default {$ImprivataType = "Not Installed"}
|
Default {$ImprivataType = "Not Installed"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$kioskRole = try {$kioskRegEntry | Select-Object -ExpandProperty KioskRole} catch{$kioskRole = $null}
|
$kioskRole = try {$kioskRegEntry | Select-Object -ExpandProperty KioskRole} catch{ $null }
|
||||||
if(!$kioskRole){
|
if (!$kioskRole) { $kioskRole = "None"}
|
||||||
$kioskRole = "None"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#TPM
|
#TPM
|
||||||
if($win32_tpm){
|
if($win32_tpm){
|
||||||
|
|
@ -352,32 +349,24 @@ function Get-PCBatchInvoke {
|
||||||
}
|
}
|
||||||
BatchInvokesProgressBar -stage 2
|
BatchInvokesProgressBar -stage 2
|
||||||
$jobs = Invoke-Command -ScriptBlock $sblock -ComputerName $OnlineComputers -SessionOption (New-PSSessionOption -NoMachineProfile -OpenTimeout 45000) -AsJob
|
$jobs = Invoke-Command -ScriptBlock $sblock -ComputerName $OnlineComputers -SessionOption (New-PSSessionOption -NoMachineProfile -OpenTimeout 45000) -AsJob
|
||||||
|
BatchInvokesProgressBar -stage 3
|
||||||
if($OfflineComputers.count -gt 0){
|
if($OfflineComputers.count -gt 0){
|
||||||
foreach($computer in $OfflineComputers){
|
foreach($computer in $OfflineComputers){
|
||||||
$jobs += Start-Job -ScriptBlock {
|
$jobs += Start-Job -ScriptBlock ${function:SCCMQueryBlock} -ArgumentList $computer
|
||||||
$offlineCompData = Get-SCCMQuery -comp $computer -NumberofComputers $OfflineComputers.count -PCID $itemIndex
|
|
||||||
if($null -eq $offlineCompData.'Last Reboot'){
|
|
||||||
$offlineCompData = Get-CMDBFallback -comp $computer
|
|
||||||
}
|
|
||||||
Write-Output $offlineCompData
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
BatchInvokesProgressBar -stage 4
|
||||||
BatchInvokesProgressBar -stage 3
|
$output += $jobs | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName
|
||||||
$output += $jobs | Receive-Job -Wait | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName
|
|
||||||
$itemIndex = 0
|
$itemIndex = 0
|
||||||
$contactedhosts = $output.Hostname
|
$contactedhosts = $output.Hostname
|
||||||
BatchInvokesProgressBar -stage 4
|
BatchInvokesProgressBar -stage 5
|
||||||
$missedhosts = $OnlineComputers | Where-Object -FilterScript {$_ -notin $contactedhosts}
|
$missedhosts = $OnlineComputers | Where-Object -FilterScript {$_ -notin $contactedhosts}
|
||||||
if($missedhosts.count -gt 0){
|
if($missedhosts.count -gt 0){
|
||||||
foreach($computer in $OfflineComputers){
|
foreach($computer in $missedhosts){
|
||||||
$offlineCompData = Get-SCCMQuery -comp $computer -NumberofComputers $OfflineComputers.count -PCID $itemIndex
|
$jobs += Start-Job -ScriptBlock ${function:SCCMQueryBlock} -ArgumentList $computer
|
||||||
if($null -eq $offlineCompData.'Last Reboot'){
|
|
||||||
$offlineCompData = Get-CMDBFallback -comp $computer
|
|
||||||
}
|
|
||||||
$output += $offlineCompData
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$output += $jobs | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName
|
||||||
|
|
||||||
return $output
|
return $output
|
||||||
|
|
||||||
|
|
@ -418,8 +407,9 @@ function BatchInvokesProgressBar {
|
||||||
)
|
)
|
||||||
switch ($stage) {
|
switch ($stage) {
|
||||||
1 { Write-Progress -Activity "Connecting to computers" -Status "$item ($currentItemIndex/$TotalItems)" -PercentComplete (($currentItemIndex/$TotalItems) * 100)}
|
1 { Write-Progress -Activity "Connecting to computers" -Status "$item ($currentItemIndex/$TotalItems)" -PercentComplete (($currentItemIndex/$TotalItems) * 100)}
|
||||||
2 { Write-Progress -Activity "Spinning up jobs" -PercentComplete ((50/100) * 100)}
|
2 { Write-Progress -Activity "Spinning up jobs" -PercentComplete ((20/100) * 100)}
|
||||||
3 { Write-Progress -Activity "Awaiting Jobs" -PercentComplete ((55/100)*100)}
|
4 { Write-Progress -Activity "Querying SCCM for offline computers" -PercentComplete ((30/100) * 100)}
|
||||||
|
3 { Write-Progress -Activity "Awaiting Jobs" -PercentComplete ((60/100)*100)}
|
||||||
4 { Write-Progress -Activity "Querying SCCM for missed computers" -PercentComplete ((75/100) * 100)}
|
4 { Write-Progress -Activity "Querying SCCM for missed computers" -PercentComplete ((75/100) * 100)}
|
||||||
Default {}
|
Default {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ function Get-PCBatchJob{
|
||||||
$Computers,
|
$Computers,
|
||||||
[switch]$printers
|
[switch]$printers
|
||||||
)
|
)
|
||||||
$modulePath = (get-item $PSScriptRoot).Parent.FullName
|
|
||||||
$modulePath = "$modulePath\Get-PC.psd1"
|
|
||||||
$TotalItems = $Computers.count
|
$TotalItems = $Computers.count
|
||||||
$ActiveJobs = @()
|
$ActiveJobs = @()
|
||||||
$itemIndex = 0
|
$itemIndex = 0
|
||||||
|
|
@ -17,15 +15,11 @@ function Get-PCBatchJob{
|
||||||
|
|
||||||
if($printers){
|
if($printers){
|
||||||
JobsProgressBar $c $itemIndex $TotalItems 1
|
JobsProgressBar $c $itemIndex $TotalItems 1
|
||||||
$ActiveJobs += Start-Job -Name $c -ArgumentList $c,$modulePath -ScriptBlock{
|
$ActiveJobs += Start-Job -Name $c -ScriptBlock ${function:Get-SHSPrinter} -ArgumentList $c
|
||||||
Import-Module $args[1] -WarningAction Ignore
|
|
||||||
get-pc $args[0] -SHSPrinter}
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
JobsProgressBar $c $itemIndex $TotalItems 1
|
JobsProgressBar $c $itemIndex $TotalItems 1
|
||||||
$ActiveJobs += Start-Job -Name $c -ArgumentList $c,$modulePath -ScriptBlock{
|
$ActiveJobs += Start-Job -Name $c -ScriptBlock ${function:get-pc} -ArgumentList $c
|
||||||
Import-Module $args[1] -WarningAction Ignore
|
|
||||||
get-pc $args[0]}
|
|
||||||
}
|
}
|
||||||
$itemIndex++
|
$itemIndex++
|
||||||
}
|
}
|
||||||
|
|
@ -33,19 +27,12 @@ function Get-PCBatchJob{
|
||||||
$completedJobs = @()
|
$completedJobs = @()
|
||||||
$itemIndex = 0
|
$itemIndex = 0
|
||||||
JobsProgressBar 'Waiting on jobs to be' $itemIndex $TotalItems 2
|
JobsProgressBar 'Waiting on jobs to be' $itemIndex $TotalItems 2
|
||||||
While(!$jobsDone){
|
While($ActiveJobs.Length){
|
||||||
$jobsDone = $true
|
$job = Wait-Job -Any $ActiveJobs
|
||||||
foreach ($job in $ActiveJobs){
|
|
||||||
if($job.State -eq 'Running'){
|
|
||||||
$jobsDone = $false
|
|
||||||
}
|
|
||||||
if($job.State -eq 'Completed' -and !$completedJobs.Contains($job)){
|
|
||||||
$itemIndex++
|
$itemIndex++
|
||||||
JobsProgressBar $job.Name $itemIndex $TotalItems 2
|
JobsProgressBar $job.Name $itemIndex $TotalItems 2
|
||||||
$completedJobs += $job
|
$completedJobs += $job
|
||||||
}
|
$ActiveJobs = $ActiveJobs | Where-Object { $_.Name -ne $job.Name }
|
||||||
}
|
|
||||||
Start-Sleep -Milliseconds 1
|
|
||||||
}
|
}
|
||||||
$itemIndex = 0
|
$itemIndex = 0
|
||||||
foreach($job in $completedJobs) {
|
foreach($job in $completedJobs) {
|
||||||
|
|
@ -54,9 +41,7 @@ function Get-PCBatchJob{
|
||||||
$output = Receive-Job $job | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName
|
$output = Receive-Job $job | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName
|
||||||
Remove-job $job
|
Remove-job $job
|
||||||
Write-Output $output
|
Write-Output $output
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function JobsProgressBar {
|
function JobsProgressBar {
|
||||||
|
|
|
||||||
284
Private/SCCMQueryBlock.ps1
Normal file
284
Private/SCCMQueryBlock.ps1
Normal file
|
|
@ -0,0 +1,284 @@
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
|
@ -21,47 +21,53 @@ function Get-SHSPrinter {
|
||||||
foreach ($printer in $printers) {
|
foreach ($printer in $printers) {
|
||||||
|
|
||||||
#Gets the printer ip and full domain name
|
#Gets the printer ip and full domain name
|
||||||
$result = Get-PrinterIP $printer
|
$hit = $false
|
||||||
|
$domains = @('.gsrmc.int.samhealth.net', '.avery.int.samhealth.net', '.sagh.int.samhealth.net', '.snlh.int.samhealth.net', '.slch.int.samhealth.net', '.spch.int.samhealth.net')
|
||||||
|
$result = Resolve-DnsName $printer -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($null -eq $result) {
|
||||||
|
$hit = $false
|
||||||
|
foreach ($domain in $domains) {
|
||||||
|
$search = "$printer$domain"
|
||||||
|
$result = Resolve-DnsName $search -ErrorAction SilentlyContinue
|
||||||
|
if ($null -ne $result) {
|
||||||
|
$hit = $true
|
||||||
|
$name = $result.Name
|
||||||
|
$ip = $result.IPAddress
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($null -eq $result) {
|
||||||
|
if ($hit -eq $false) {
|
||||||
|
$ip = $null
|
||||||
|
$name = $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$name = $result.Name
|
||||||
|
$ip = $result.IPAddress
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [ordered]@{Hostname = $printer
|
||||||
|
IP = $ip
|
||||||
|
Path = $name
|
||||||
|
}
|
||||||
|
|
||||||
#CMDB Data
|
#CMDB Data
|
||||||
|
|
||||||
$cmdbRecord = Get-LANDeskCMDBItem -Name $printer
|
|
||||||
if ($cmdbRecord.values._SHSLocation3.Length -gt $cmdbRecord.values._SHSCalcLocationString.Length) {
|
|
||||||
$locationData = $cmdbRecord.values._SHSLocation3
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$locationData = $cmdbRecord.values._SHSCalcLocationString
|
|
||||||
}
|
|
||||||
if ($cmdbRecord) {
|
|
||||||
$CMDB_POA = $cmdbRecord.values._SHSPOANumber
|
|
||||||
$CMDB_AssetTag = $cmdbRecord.values._SHSAssetTag
|
|
||||||
$CMDB_Location = $locationData
|
|
||||||
$CMDB_MAC = $cmdbRecord.values._SHSMACAddress
|
|
||||||
$CMDB_model = $cmdbRecord.values._Model
|
|
||||||
$CMDB_serial = $cmdbRecord.values._SerialNumber
|
|
||||||
$CMDB_IP = $cmdbRecord.values._IPAddress
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$CMDB_POA = "*CMDB Mismatch - check CMDB*"
|
|
||||||
$CMDB_AssetTag = "*CMDB Mismatch - check CMDB*"
|
|
||||||
$CMDB_Location = "*CMDB Mismatch - check CMDB*"
|
|
||||||
$CMDB_MAC = "*CMDB Mismatch - check CMDB*"
|
|
||||||
$CMDB_model = "*CMDB Mismatch - check CMDB*"
|
|
||||||
$CMDB_serial = "*CMDB Mismatch - check CMDB*"
|
|
||||||
$CMDB_IP = "*CMDB Mismatch - check CMDB*"
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($null -ne $result.IP) {
|
if ($null -ne $result.IP) {
|
||||||
|
|
||||||
|
|
||||||
$printerip = $result.IP
|
$printerip = $result.IP
|
||||||
$domainName = $result.Path
|
$domainName = $result.Path
|
||||||
|
|
||||||
#checks to see if the printer is online
|
#checks to see if the printer is online
|
||||||
$online = Test-Connection $printerip -ErrorAction SilentlyContinue
|
$online = Test-Connection $printerip -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($online) {
|
if ($online) {
|
||||||
#opens snmp connection to the printer
|
#opens snmp connection to the printer
|
||||||
$snmp.open($printerip, 'public', 2, 3000)
|
$snmp.open($printerip, 'public', 2, 3000)
|
||||||
|
|
@ -274,9 +280,6 @@ function Get-SHSPrinter {
|
||||||
#Addresses = $addr
|
#Addresses = $addr
|
||||||
PageCount = $pagecount
|
PageCount = $pagecount
|
||||||
Supplies = $supplies
|
Supplies = $supplies
|
||||||
'CMDB POA' = $CMDB_POA
|
|
||||||
'CMDB AssetTag' = $CMDB_AssetTag
|
|
||||||
'CMDB Location' = $CMDB_Location
|
|
||||||
}
|
}
|
||||||
$obj = New-Object -TypeName PSObject -Property $props
|
$obj = New-Object -TypeName PSObject -Property $props
|
||||||
$snmp.close()
|
$snmp.close()
|
||||||
|
|
@ -285,27 +288,19 @@ function Get-SHSPrinter {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($CMDB_IP) {
|
|
||||||
$offlineIP = 'CMDB IP - ' + $CMDB_IP
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$offlineIP = 'No DNS Entry'
|
|
||||||
}
|
|
||||||
$props = [Ordered]@{
|
$props = [Ordered]@{
|
||||||
Machine = $printer
|
Machine = $printer
|
||||||
Status = 'No DNS Entry'
|
Status = 'No DNS Entry'
|
||||||
IP = $offlineIP
|
IP = 'No DNS Entry'
|
||||||
DomainName = 'No DNS Entry'
|
DomainName = 'No DNS Entry'
|
||||||
MAC = $CMDB_MAC
|
MAC = 'No DNS Entry'
|
||||||
Model = $CMDB_model
|
Model = 'No DNS Entry'
|
||||||
Serial = $CMDB_serial
|
Serial = 'No DNS Entry'
|
||||||
#Comment = $comment
|
#Comment = $comment
|
||||||
Color = 'No DNS Entry'
|
Color = 'No DNS Entry'
|
||||||
Trays = 'No DNS Entry'
|
Trays = 'No DNS Entry'
|
||||||
PageCount = 'No DNS Entry'
|
PageCount = 'No DNS Entry'
|
||||||
'CMDB POA' = $CMDB_POA
|
|
||||||
'CMDB AssetTag' = $CMDB_AssetTag
|
|
||||||
'CMDB Location' = $CMDB_Location
|
|
||||||
}
|
}
|
||||||
$obj = New-Object -TypeName PSObject -Property $props
|
$obj = New-Object -TypeName PSObject -Property $props
|
||||||
$snmp.close()
|
$snmp.close()
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#region Module Import Block
|
#region Module Import Block
|
||||||
|
|
||||||
#$ErrorActionPreference = 'SilentlyContinue'
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
#DevStage can take either Dev or Prod as values
|
#DevStage can take either Dev or Prod as values
|
||||||
$devStage = 'Dev'
|
$devStage = 'Dev'
|
||||||
#Locations for dev build and prod build
|
#Locations for dev build and prod build
|
||||||
|
|
@ -40,6 +40,7 @@ Function Get-PC {
|
||||||
-Apps | shows the installed applications on the computer
|
-Apps | shows the installed applications on the computer
|
||||||
-AppDiff | shows the installed applications that are not in the standard image
|
-AppDiff | shows the installed applications that are not in the standard image
|
||||||
-Bypass | used in conjuction with remote viewer will bypass user prompt
|
-Bypass | used in conjuction with remote viewer will bypass user prompt
|
||||||
|
-ClearCCMCache | clears CCM cache, may fix software center
|
||||||
-Devices | shows connected monitors and usb devices
|
-Devices | shows connected monitors and usb devices
|
||||||
-EventLog | pulls up errors in the event log for the last x days
|
-EventLog | pulls up errors in the event log for the last x days
|
||||||
-Excel | exports collected data to csv and opens it with excel
|
-Excel | exports collected data to csv and opens it with excel
|
||||||
|
|
@ -48,6 +49,7 @@ Function Get-PC {
|
||||||
-InstallNet35 | installs .Net 3.5
|
-InstallNet35 | installs .Net 3.5
|
||||||
-LogOffUser | remotely logs off user
|
-LogOffUser | remotely logs off user
|
||||||
-Monitor | monitors computers for changes in status
|
-Monitor | monitors computers for changes in status
|
||||||
|
-NextPrinterName | generates next open printer name
|
||||||
-Orion | opens orion to the mac address of the pc
|
-Orion | opens orion to the mac address of the pc
|
||||||
-PCCleanup | removes temp files and inactive user profiles
|
-PCCleanup | removes temp files and inactive user profiles
|
||||||
-PCReboot | reboots computer
|
-PCReboot | reboots computer
|
||||||
|
|
@ -61,6 +63,7 @@ Function Get-PC {
|
||||||
-SHSPrinterweb | pulls data about a printer and opens web interface and orion
|
-SHSPrinterweb | pulls data about a printer and opens web interface and orion
|
||||||
-SHSUser | get data about a user from AD, can accept username or employee number
|
-SHSUser | get data about a user from AD, can accept username or employee number
|
||||||
-Tableview | output the results in a table
|
-Tableview | output the results in a table
|
||||||
|
-UninstallProgram | remotely uninstall a program from a pc
|
||||||
-Usb | shows installed usb devices
|
-Usb | shows installed usb devices
|
||||||
-UserProfileBackup | backups and restores user profiles
|
-UserProfileBackup | backups and restores user profiles
|
||||||
-ViewerRemote | remote into the computer using RemoteViewer
|
-ViewerRemote | remote into the computer using RemoteViewer
|
||||||
|
|
@ -85,6 +88,7 @@ Function Get-PC {
|
||||||
[Switch]$Apps,
|
[Switch]$Apps,
|
||||||
[Switch]$AppDiff,
|
[Switch]$AppDiff,
|
||||||
[Switch]$Bypass,
|
[Switch]$Bypass,
|
||||||
|
[Switch]$ClearCCMCache,
|
||||||
[switch]$Devices,
|
[switch]$Devices,
|
||||||
[Switch]$EventLog,
|
[Switch]$EventLog,
|
||||||
[switch]$Excel,
|
[switch]$Excel,
|
||||||
|
|
@ -103,8 +107,8 @@ Function Get-PC {
|
||||||
[Switch]$PCRename,
|
[Switch]$PCRename,
|
||||||
[Switch]$Quiet,
|
[Switch]$Quiet,
|
||||||
[Switch]$RemoteDesktopApp,
|
[Switch]$RemoteDesktopApp,
|
||||||
[Switch]$Resources,
|
|
||||||
[Switch]$ResetRepository,
|
[Switch]$ResetRepository,
|
||||||
|
[Switch]$Resources,
|
||||||
[Switch]$PrinterPurge,
|
[Switch]$PrinterPurge,
|
||||||
[Switch]$SCCM,
|
[Switch]$SCCM,
|
||||||
[Switch]$SHSPrinter,
|
[Switch]$SHSPrinter,
|
||||||
|
|
@ -139,6 +143,12 @@ Function Get-PC {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($Jobsprinters) {
|
||||||
|
#runs the printer query as a set of jobs
|
||||||
|
$outPutArray = Get-PCBatchJob($ComputerName) -printers
|
||||||
|
Write-Output $outPutArray
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
$getPCComputers = @() #List of computers that will get a batch query
|
$getPCComputers = @() #List of computers that will get a batch query
|
||||||
$outPutArray = @() #For use near the end of the script to output to users screen in a specified format
|
$outPutArray = @() #For use near the end of the script to output to users screen in a specified format
|
||||||
|
|
@ -155,7 +165,7 @@ Function Get-PC {
|
||||||
|
|
||||||
$oldcomp = $comp
|
$oldcomp = $comp
|
||||||
$comp,$msg = Get-Hostname $comp
|
$comp,$msg = Get-Hostname $comp
|
||||||
if ($msg) {
|
if ($msg -and -not $SHSPrinter) {
|
||||||
Write-Host "`n$msg" -ForegroundColor Red
|
Write-Host "`n$msg" -ForegroundColor Red
|
||||||
|
|
||||||
$props = [Ordered]@{
|
$props = [Ordered]@{
|
||||||
|
|
@ -460,6 +470,16 @@ Function Get-PC {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($ClearCCMCache) {
|
||||||
|
|
||||||
|
if ($compStatus -ne 'Online') {
|
||||||
|
Write-Warning "$comp is $compStatus unable to proccess command"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
Invoke-ClearCCMCache $comp
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
#Will log off the current logged in user for the designated PC
|
#Will log off the current logged in user for the designated PC
|
||||||
#Adapted from Josh Gobens Logoff Script
|
#Adapted from Josh Gobens Logoff Script
|
||||||
if ($LogOffUser) {
|
if ($LogOffUser) {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
Patch: 2024-07-26
|
||||||
|
-Refactors
|
||||||
|
-Update BatchInvokes to utilize jobs for up to 4x speedup
|
||||||
|
-Add ClearCCMCache
|
||||||
|
|
||||||
Patch: 2024-07-15
|
Patch: 2024-07-15
|
||||||
-Add UninstallProgram to uninstall a program from the target pc
|
-Add UninstallProgram to uninstall a program from the target pc
|
||||||
-Fix Apps to report version and publisher correctly
|
-Fix Apps to report version and publisher correctly
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue