CMDB flag, Apps computer column, and coast hostname fix

This commit is contained in:
Zachary Gorman 2024-08-29 09:44:47 -07:00
parent 96c7c6244b
commit e30dfa2aaa
7 changed files with 52 additions and 15 deletions

View file

@ -12,7 +12,7 @@
RootModule = 'Get-PC.psm1'
# Version number of this module.
ModuleVersion = '0.4.3'
ModuleVersion = '0.4.4'
# Supported PSEditions
# CompatiblePSEditions = @()

View file

@ -5,6 +5,7 @@
#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
} else {
@ -12,6 +13,7 @@
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
}

View file

@ -134,10 +134,10 @@ function Get-CMDBFallback {
Model = $cmdbData.Model + ' (' + $cmdbData.ivnt_assetsubtype + ')'
'OS' = $cmdbData.OperatingSystem + " " + $cmdbData.OSMajorVersion
'OS Build' = $cmdbData.OSMajorVersion
'BIOS Ver' = $cmdbData.BIOSVersion + " ($($cmdbData.BiosDate))"
'BIOS Ver' = "$($cmdbData.BIOSVersion) ($($cmdbData.BiosDate))"
Encryption = $cmdbData.ivnt_EncryptionState
'Free Space' = $diskData.FreeSpace + ' GB / ' + $diskData.capacity + ' GB'
'RAM' = $MemoryTotal+ " GB "
'Free Space' = "$($diskData.FreeSpace) GB / $($diskData.capacity) GB"
'RAM' = "$MemoryTotal GB "
'SSO Client' = "Not Available"
# 'Kiosk Role' = "Not Available"
'Asset Tag' = $cmdbData.AssetTag

View file

@ -13,7 +13,7 @@ function Get-Hostname ([string]$name) {
if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") {
$res = Resolve-DnsName $name
if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) {
return $Matches[1],''
return $Matches[0],''
} else {
$errMsg += "$name IP Address couldn't be resolved to hostname"
}
@ -34,5 +34,10 @@ function Get-Hostname ([string]$name) {
else { $errMsg += "$name MAC Address not found in SCCM"}
}
$cmdbMatches = Find-ISMBO -bo cis -SearchQuery $name
if ($cmdbMatches -and $cmdbMatches.Count -lt 2) {
return $cmdbMatches.Name,''
}
return $name, $errMsg
}

View file

@ -442,10 +442,10 @@ function Get-SCCM_Apps($ComputerName) {
SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'"
$64apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX64Query |
Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName
Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName Computer -NotePropertyValue $ComputerName -PassThru | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName
$86apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX86Query |
Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName
Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName Computer -NotePropertyValue $ComputerName -PassThru | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName
return $86apps, $64apps
}

View file

@ -21,6 +21,8 @@ elseif ($devStage -eq "Dev") {
$deployedVersion = (Test-ModuleManifest $getPCDevBuildPath).Version
}
$getPCWrappedPath = '\\int.samhealth.net\files\TEAM\SHSISDesktopSolutions\Powershell\Get-PC_Update_2023\Get-PC-Wrapped\backlog.txt'
#lets user know when get-pc has been imported and what version they are running
Write-Host "`nGet-PC Module Version $Version [$devStage] Loaded." -ForegroundColor Green
if ($Version -ne $deployedVersion) {
@ -41,6 +43,7 @@ Function Get-PC {
-AppDiff | shows the installed applications that are not in the standard image
-Bypass | used in conjuction with remote viewer will bypass user prompt
-ClearCCMCache | clears CCM cache, may fix software center
-CMDB | only queries CMDB for info
-Devices | shows connected monitors and usb devices
-EventLog | pulls up errors in the event log for the last x days
-Excel | exports collected data to csv and opens it with excel
@ -89,6 +92,7 @@ Function Get-PC {
[Switch]$AppDiff,
[Switch]$Bypass,
[Switch]$ClearCCMCache,
[Switch]$CMDB,
[switch]$Devices,
[Switch]$EventLog,
[switch]$Excel,
@ -124,6 +128,17 @@ Function Get-PC {
[Switch]$WinProfileRebuild
)
<#
#Data collection for Get-PC Wrapped TM
$invokeData = @{
Hostname = $env:COMPUTERNAME
Username = $env:USERNAME
Datetime = Get-Date -Format 'yyyy-MM-ddThh:mm:ss.fffffff'
Parameters = $MyInvocation.BoundParameters
}
Add-Content -Path $getPCWrappedPath -Value $(ConvertTo-Json -Compress $invokeData)
#>
## Define which Spark Record Properties are Returned
$Spark_Property_Return = @(
"Name",
@ -136,10 +151,12 @@ Function Get-PC {
"Status"
)
<#
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "Get-PC requires powershell to be run as administrator. Please re-launch powershell as administrator."
break
}
#>
# Stuff only run once
if ($Update) {
@ -198,14 +215,17 @@ Function Get-PC {
Write-Host "Starting CMDB Wildcard Search..."
# $searchResults = Search-CMDB -hostname $ComputerName.Replace('*','') | Sort-Object -Property Hostname
$output = @()
foreach ($comp in $ComputerName) {
$searchResults = Find-ISMBO -BusinessObject "cis" -SearchQuery $comp | Sort-Object -Property Name
$searchResults = Find-ISMBO -BusinessObject "cis" -SearchQuery $ComputerName.Replace('*','') | Sort-Object -Property Name
Write-Output $searchResults | Select-Object $Spark_Property_Return
if($TableView){
$searchResults | Select-Object $Spark_Property_Return | Out-GridView -Title 'Get-PC Wildcard Search'
$output += Write-Output $searchResults | Select-Object $Spark_Property_Return
}
return
#$searchResults = Find-ISMBO -BusinessObject "cis" -SearchQuery $ComputerName.Replace('*','') | Sort-Object -Property Name
if($TableView){
$output | Out-GridView -Title 'Get-PC Wildcard Search'
}
return $output
}
@ -222,7 +242,6 @@ Function Get-PC {
continue
}
$oldcomp = $comp
$comp,$msg = Get-Hostname $comp
if ($msg -and -not $SHSPrinter) {
Write-Host "`n$msg" -ForegroundColor Red
@ -257,6 +276,11 @@ Function Get-PC {
continue
}
if ($CMDB) {
$outputArray += Get-CMDBFallback $comp
continue
}
#DREW SUCKS
#Pulls basic SNMP Data from printer $comp

View file

@ -1,3 +1,9 @@
Patch: 2024-08-29
-Add CMDB flag to just query CMDB for fields
-Fix bug in CMDB Fallback not reporting RAM correctly
-Apps has the Computer column again
-Fix Coast hostnames are checked against CMDB before rejecting as bad SN
Patch: 2024-08-14
-Add CMDB fallback added when hostname not in SCCM
-Fix Get-Hostname to query cmdb for asset tags if not in SCCM