Merge branch 'master' of S:/Powershell/Get-PC_Update_2023/Get-PC
This commit is contained in:
commit
7a01bf51b0
|
|
@ -13,13 +13,14 @@ function Get-AppDiff {
|
|||
param(
|
||||
[Parameter(Mandatory)]
|
||||
$pc,
|
||||
$CompStatus = $offline,
|
||||
$TableView = $false
|
||||
)
|
||||
|
||||
# Compares a pc's apps with a list of expected apps to see if the pc has any
|
||||
# extra apps that we need to consider downloading
|
||||
|
||||
$apps = Get-Apps $pc
|
||||
$apps = Get-Apps $pc $CompStatus
|
||||
Write-Progress -Activity "Filtering out standard apps from $pc" -Status 'Removing version numbers and loading reference' -PercentComplete 10 -ParentId 1
|
||||
$apps = Remove-Version $apps
|
||||
# Open example file
|
||||
|
|
|
|||
|
|
@ -1,58 +1,34 @@
|
|||
Function Get-Apps($ComputerName, $TableView) {
|
||||
|
||||
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1
|
||||
$86apps, $64apps = Get-SCCM_Apps $ComputerName
|
||||
|
||||
# Assumes 64 bit system, registry keys may be different on 32 bit systems
|
||||
Function Get-Apps($ComputerName, $CompStatus, $TableView) {
|
||||
if ($CompStatus -eq "Online") {
|
||||
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying local apps' -PercentComplete 30 -ParentId 1
|
||||
$sblock = {
|
||||
$32RegPath = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
|
||||
$64RegPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
|
||||
$apps = Get-ItemProperty $32RegPath |
|
||||
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru |
|
||||
Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru
|
||||
$apps += Get-ItemProperty $64RegPath |
|
||||
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru |
|
||||
Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru
|
||||
$apps += Get-Package |
|
||||
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru
|
||||
$apps | Sort-Object 'x86/x64',DisplayName -Unique
|
||||
}
|
||||
#Checks if local computer
|
||||
if ($ComputerName -eq $env:COMPUTERNAME) {
|
||||
$localapps = Get-Package -ProviderName Programs -IncludeWindowsInstaller |
|
||||
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru |
|
||||
Select-Object @{N='DisplayName';E={$_.Name}},* |
|
||||
Sort-Object -Property DisplayName
|
||||
$apps = Invoke-Command -ScriptBlock $sblock | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
|
||||
} else {
|
||||
#Checks if pc is online so Invoke doesn't hang on offline pc
|
||||
if (Test-Connection -ComputerName $ComputerName -Count 1) {
|
||||
$localapps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock {
|
||||
Get-Package -ProviderName Programs -IncludeWindowsInstaller |
|
||||
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru |
|
||||
Select-Object @{N='DisplayName';E={$_.Name}},* |
|
||||
Sort-Object -Property DisplayName
|
||||
$apps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock $sblock |
|
||||
Select-Object -Property * -ExcludeProperty PSComputerName | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Combining apps from SCCM' -PercentComplete 50 -ParentId 1
|
||||
$out = $86apps + $64apps
|
||||
$apps = @()
|
||||
foreach ($item in $out) {
|
||||
$a = New-Object -TypeName PSCustomObject
|
||||
$a.PSObject.TypeNames.Insert(0, 'GetPC.App')
|
||||
Copy-Property -From $item -To $a
|
||||
$apps += $a
|
||||
}
|
||||
|
||||
# Blank entry for visual break
|
||||
$a = [PSCustomObject]@{
|
||||
DisplayName = ""
|
||||
}
|
||||
$a.PSObject.TypeNames.Insert(0, 'GetPC.App')
|
||||
$apps += $a
|
||||
|
||||
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Combining apps from local query' -PercentComplete 75 -ParentId 1
|
||||
# Grab apps that are only returned by local query
|
||||
if ($out) {
|
||||
$localOnly = Compare-Object $localapps $out -Property DisplayName -PassThru | Where-Object {$_.SideIndicator -eq '<='}
|
||||
} else {
|
||||
$localOnly = $localapps
|
||||
}
|
||||
foreach ($item in $localOnly) {
|
||||
$a = New-Object -TypeName PSCustomObject
|
||||
$a.PSObject.TypeNames.Insert(0, 'GetPC.App')
|
||||
Copy-Property -From $item -To $a
|
||||
$apps += $a
|
||||
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1
|
||||
$86apps, $64apps = Get-SCCM_Apps $ComputerName
|
||||
$apps = ($86apps + $64apps) | Sort-Object 'x86/x64',DisplayName -Unique | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
|
||||
}
|
||||
|
||||
|
||||
if ($TableView) {
|
||||
$apps | Out-GridView -Title "Get-PC Apps - $ComputerName"
|
||||
}
|
||||
|
|
@ -61,10 +37,3 @@
|
|||
}
|
||||
Write-Progress -Activity "Getting apps for $ComputerName" -Completed
|
||||
}
|
||||
function Copy-Property ($From, $To) {
|
||||
|
||||
$properties = Get-Member -InputObject $From -MemberType NoteProperty
|
||||
foreach ($p in $properties) {
|
||||
$To | Add-Member -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force
|
||||
}
|
||||
}
|
||||
|
|
@ -42,30 +42,8 @@ $Headers = @{
|
|||
$FindLastHardwareScanSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindLastHardwareScanQuery | Select-Object -ExpandProperty LastHardwareScan
|
||||
|
||||
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
|
||||
Write-Progress -Activity "Getting SCCM data for $comp" -Completed
|
||||
return
|
||||
}
|
||||
|
||||
$Year = $FindLastHardwareScanSCCM.substring(0,4)
|
||||
|
|
@ -248,7 +226,7 @@ $Headers = @{
|
|||
$cmdbData = $Query.Value
|
||||
} else {
|
||||
$cmdbData = @{
|
||||
Loc = "CMDB Mismatch!"
|
||||
SHS_LocationDetails = "CMDB Mismatch!"
|
||||
Status = "CMDB Mismatch!"
|
||||
}
|
||||
}
|
||||
|
|
@ -256,7 +234,7 @@ $Headers = @{
|
|||
#Write-Host $_.Exception.Message
|
||||
#Write-Warning "Failed querying Spark!"
|
||||
$cmdbData = @{
|
||||
Loc = "Failed querying Spark!"
|
||||
SHS_LocationDetails = "Failed querying Spark!"
|
||||
Status = "Failed querying Spark!"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,17 +13,54 @@ function Get-SHSPrinter {
|
|||
[string]$printer
|
||||
)
|
||||
|
||||
Write-Progress -Activity "Getting printer details for $name" -Status 'Getting IP Address' -PercentComplete 10 -ParentId 1
|
||||
# Spark connection params
|
||||
$Tenant = 'https://samaritanhealth-amc.ivanticloud.com'
|
||||
$Headers = @{
|
||||
"Content-Type" = "application/json"
|
||||
"Authorization" = 'rest_api_key=EB68123D62F8489295C807353C92D75B'
|
||||
"Accept" = "*/*"
|
||||
"Accept-Encoding" = "gzip, deflate, br"
|
||||
}
|
||||
|
||||
Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting IP Address' -PercentComplete 10 -ParentId 1
|
||||
$snmp = New-Object -ComObject olePrn.OleSNMP
|
||||
|
||||
#Gets the printer ip and full domain name
|
||||
$result = Get-PrinterIP $printer
|
||||
$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){
|
||||
foreach ($domain in $domains) {
|
||||
$search = "$printer$domain"
|
||||
$result = Resolve-DnsName $search -ErrorAction SilentlyContinue
|
||||
if($null -ne $result){ break }
|
||||
}
|
||||
}
|
||||
|
||||
#CMDB Data
|
||||
|
||||
Write-Progress -Activity "Getting printer details for $name" -Status 'Getting CMDB data' -PercentComplete 20 -ParentId 1
|
||||
Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting CMDB data' -PercentComplete 20 -ParentId 1
|
||||
# $cmdbRecord = Get-LANDeskCMDBItem -Name $printer
|
||||
$cmdbRecord = Search-ISMBO -BO cis -filter "Name eq '$Printer'" -RawFilter
|
||||
$timeout = if ($SparkQueryTimeoutSec) {$SparkQueryTimeoutSec} else {5}
|
||||
$uri = "$Tenant/api/odata/businessobject/cis`?`$filter=Name eq '$printer'&`$top=1&`$skip=0"
|
||||
try {
|
||||
$Query = Invoke-RestMethod -Method GET -uri $uri -headers $Headers -TimeoutSec $timeout
|
||||
if ($Query) {
|
||||
$cmdbData = $Query.Value
|
||||
} else {
|
||||
$cmdbData = @{
|
||||
SHS_LocationDetails = "CMDB Mismatch!"
|
||||
Status = "CMDB Mismatch!"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
#Write-Host $_.Exception.Message
|
||||
#Write-Warning "Failed querying Spark!"
|
||||
$cmdbData = @{
|
||||
SHS_LocationDetails = "Failed querying Spark!"
|
||||
Status = "Failed querying Spark!"
|
||||
}
|
||||
}
|
||||
|
||||
$LocationConstructors = @(
|
||||
"SHS_AssetLocality",
|
||||
|
|
@ -33,66 +70,76 @@ function Get-SHSPrinter {
|
|||
"SHS_LocationDetails"
|
||||
)
|
||||
|
||||
$LocationData = Foreach ($Loc in $LocationConstructors) {
|
||||
$LocationData = Foreach($Loc in $LocationConstructors){
|
||||
|
||||
if ($Loc -eq 'SHS_Floor') {
|
||||
$(if ($cmdbRecord.$Loc -match '-') { $cmdbRecord.$Loc.split('-')[-1] + " Floor" } else { $cmdbRecord.$Loc })
|
||||
}
|
||||
elseif (![string]::IsNullOrEmpty($cmdbRecord.$Loc)) {
|
||||
$cmdbRecord.$Loc
|
||||
if ($Loc -eq 'SHS_Floor'){
|
||||
$(if ($cmdbData.$Loc -match '-'){$cmdbData.$Loc.split('-')[-1] + " Floor"} else{$cmdbData.$Loc})
|
||||
} elseif (![string]::IsNullOrEmpty($cmdbData.$Loc)){
|
||||
$cmdbData.$Loc
|
||||
}
|
||||
}
|
||||
|
||||
$LocationData = $LocationData -join ' | '
|
||||
|
||||
# $locationData = $cmdbRecord.SHS_AssetLocality + " | " + $cmdbRecord.ivnt_Location + " | " + + " | " + $cmdbRecord.SHS_Department + " | " + $cmdbRecord.SHS_LocationDetails
|
||||
# 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
|
||||
|
||||
if ($cmdbData) {
|
||||
### Spark Properties
|
||||
$CMDB_POA = $cmdbRecord.SHS_POANumber
|
||||
$CMDB_AssetTag = $cmdbRecord.AssetTag
|
||||
$CMDB_POA = $cmdbData.SHS_POANumber
|
||||
$CMDB_AssetTag = $cmdbData.AssetTag
|
||||
$CMDB_Location = $locationData
|
||||
$CMDB_MAC = $cmdbRecord.MACAddress
|
||||
$CMDB_model = $cmdbRecord.Model
|
||||
$CMDB_serial = $cmdbRecord.SerialNumber
|
||||
$CMDB_IP = $cmdbRecord.IPAddress
|
||||
$CMDB_MAC = $cmdbData.MACAddress
|
||||
$CMDB_model = $cmdbData.Model
|
||||
$CMDB_serial = $cmdbData.SerialNumber
|
||||
$CMDB_IP = $cmdbData.IPAddress
|
||||
$CMDB_Status = $cmdbData.Status
|
||||
}
|
||||
|
||||
if ($null -eq $result.IPAddress) {
|
||||
if ($CMDB_IP) {
|
||||
$offlineIP = 'CMDB IP - ' + $CMDB_IP
|
||||
}
|
||||
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*"
|
||||
$offlineIP = 'No DNS Entry'
|
||||
}
|
||||
$props = [Ordered]@{
|
||||
Machine = $printer
|
||||
Status = 'No DNS Entry'
|
||||
IP = $offlineIP
|
||||
DomainName = 'No DNS Entry'
|
||||
MAC = $CMDB_MAC
|
||||
Model = $CMDB_model
|
||||
Serial = $CMDB_serial
|
||||
#Comment = $comment
|
||||
Color = 'No DNS Entry'
|
||||
Trays = 'No DNS Entry'
|
||||
PageCount = 'No DNS Entry'
|
||||
'CMDB POA' = $CMDB_POA
|
||||
'CMDB AssetTag' = $CMDB_AssetTag
|
||||
'CMDB Location' = $CMDB_Location
|
||||
'CMDB Status' = $CMDB_Status
|
||||
}
|
||||
$obj = New-Object -TypeName PSObject -Property $props
|
||||
return $obj
|
||||
}
|
||||
|
||||
if ($null -ne $result.IP) {
|
||||
|
||||
Write-Progress -Activity "Getting printer details for $name" -Status 'Connecting to printer' -PercentComplete 30 -ParentId 1
|
||||
|
||||
$printerip = $result.IP
|
||||
$domainName = $result.Path
|
||||
$printerip = $result.IPAddress
|
||||
$null = $result.Name -match '[^.]*\.(.*)'
|
||||
$domainName = $Matches[1]
|
||||
|
||||
#checks to see if the printer is online
|
||||
$online = Test-Connection $printerip -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
|
||||
if ($online) {
|
||||
if (-not $online) {
|
||||
$status = "Offline"
|
||||
$MAC = $CMDB_MAC
|
||||
$model = $CMDB_model
|
||||
$serial = $CMDB_serial
|
||||
$color = "Offline"
|
||||
$trays = "Offline"
|
||||
$pagecount = "Offline"
|
||||
}
|
||||
else {
|
||||
#opens snmp connection to the printer
|
||||
$snmp.open($printerip, 'public', 2, 3000)
|
||||
|
||||
|
|
@ -339,15 +386,6 @@ function Get-SHSPrinter {
|
|||
|
||||
}#end if ($model)
|
||||
}
|
||||
else {
|
||||
$status = "Offline"
|
||||
$MAC = $CMDB_MAC
|
||||
$model = $CMDB_model
|
||||
$serial = $CMDB_serial
|
||||
$color = "Offline"
|
||||
$trays = "Offline"
|
||||
$pagecount = "Offline"
|
||||
}
|
||||
|
||||
$props = [Ordered]@{
|
||||
Machine = $printer
|
||||
|
|
@ -368,90 +406,16 @@ function Get-SHSPrinter {
|
|||
'CMDB POA' = $CMDB_POA
|
||||
'CMDB AssetTag' = $CMDB_AssetTag
|
||||
'CMDB Location' = $CMDB_Location
|
||||
'CMDB Status' = $CMDB_Status
|
||||
}
|
||||
$obj = New-Object -TypeName PSObject -Property $props
|
||||
$snmp.close()
|
||||
Write-Progress -Activity "Getting printer details for $name" -Completed
|
||||
return $obj
|
||||
}#end if ($printerIp)
|
||||
if ($CMDB_IP) {
|
||||
$offlineIP = 'CMDB IP - ' + $CMDB_IP
|
||||
}
|
||||
else {
|
||||
$offlineIP = 'No DNS Entry'
|
||||
}
|
||||
$props = [Ordered]@{
|
||||
Machine = $printer
|
||||
Status = 'No DNS Entry'
|
||||
IP = $offlineIP
|
||||
DomainName = 'No DNS Entry'
|
||||
MAC = $CMDB_MAC
|
||||
Model = $CMDB_model
|
||||
Serial = $CMDB_serial
|
||||
#Comment = $comment
|
||||
Color = 'No DNS Entry'
|
||||
Trays = '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
|
||||
$snmp.close()
|
||||
return $obj
|
||||
|
||||
}
|
||||
|
||||
|
||||
function Get-PrinterIP {
|
||||
|
||||
param (
|
||||
[parameter(ValueFromPipeline)]
|
||||
[string]$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($result -eq $null){
|
||||
$hit = $false
|
||||
foreach ($domain in $domains) {
|
||||
$search = "$printer$domain"
|
||||
$result = Resolve-DnsName $search -ErrorAction SilentlyContinue
|
||||
if($result -ne $null){
|
||||
$hit = $true
|
||||
$name = $result.Name
|
||||
$ip = $result.IPAddress
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($result -eq $null){
|
||||
if($hit -eq $false){
|
||||
$ip = $null
|
||||
$name = $null
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$name = $result.Name
|
||||
$ip = $result.IPAddress
|
||||
|
||||
}
|
||||
|
||||
$props = [ordered]@{Hostname=$printer
|
||||
IP=$ip
|
||||
Path=$name
|
||||
}
|
||||
$obj = New-Object -TypeName PSObject -Property $props
|
||||
|
||||
return $obj
|
||||
|
||||
|
||||
}
|
||||
|
||||
function Start-SHSPrinterWeb {
|
||||
param(
|
||||
$printer
|
||||
|
|
|
|||
|
|
@ -70,7 +70,9 @@ Function Get-PC {
|
|||
-Excel | exports collected data to csv and opens it with excel
|
||||
-Filesystem | access the file system
|
||||
-GPUpdate | runs a gpupdate
|
||||
-HostnamesByPrinter | grabs all hostnames that have the requested printer installed on it
|
||||
-InstallNet35 | installs .Net 3.5
|
||||
-JobsPrinters | optimized version of shsprinter for querying many printers
|
||||
-LogOffUser | remotely logs off user
|
||||
-Monitor | monitors computers for changes in status
|
||||
-NextPrinterName | generates next open printer name
|
||||
|
|
@ -531,12 +533,12 @@ begin {
|
|||
|
||||
#Pulls a list of installed programs from SCCM and Get-Package
|
||||
if ($Apps) {
|
||||
Get-Apps $comp $TableView
|
||||
Get-Apps $comp $compStatus $TableView
|
||||
continue
|
||||
}
|
||||
|
||||
if ($AppDiff) {
|
||||
Get-AppDiff $comp $TableView
|
||||
Get-AppDiff $comp $compStatus $TableView
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
Patch 2025-2-13
|
||||
-Add HostnamesByPrinter to list hostnames with printer installed
|
||||
-Add JobsPrinters to query many printers faster
|
||||
-Update Apps no longer queries sccm when workstation is online
|
||||
|
||||
Patch: 2025-2-4
|
||||
-Add ADGroups flag to list out a workstation or user's AD groups
|
||||
-Fix Devices reports correct ports for Dell P2425H
|
||||
|
|
|
|||
Loading…
Reference in a new issue