diff --git a/.gitignore b/.gitignore index 60ba4dc..81e899b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode -Get-PC VS Code.code-workspace \ No newline at end of file +Get-PC VS Code.code-workspace +ISMTools \ No newline at end of file diff --git a/Get-PC/Private/BatchInvokes.ps1 b/Get-PC/Private/BatchInvokes.ps1 index fe8fcba..b9f5068 100644 --- a/Get-PC/Private/BatchInvokes.ps1 +++ b/Get-PC/Private/BatchInvokes.ps1 @@ -5,8 +5,6 @@ function Get-PCBatchInvoke { [string[]] $Computers ) - $Tenant = (Connect-ISM)[1] - $Headers = (Connect-ISM)[0] $OnlineComputers = @() $OfflineComputers = @() diff --git a/Get-PC/Private/Get-Hostname.ps1 b/Get-PC/Private/Get-Hostname.ps1 index 4900586..0930d8a 100644 --- a/Get-PC/Private/Get-Hostname.ps1 +++ b/Get-PC/Private/Get-Hostname.ps1 @@ -12,7 +12,7 @@ function Get-Hostname ([string]$name) { if ($res) { Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1 return $res,'' - } else { $errMsg += "$name Asset Tag not in SMBIOS`n" } + } else { $errMsg += "Asset Tag not in SMBIOS`n" } # We don't check CMDB asset tags here because they often resolve to # something other than the hostname, like the asset tag itself } @@ -24,7 +24,7 @@ function Get-Hostname ([string]$name) { Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1 return $Matches[0],'' } else { - $errMsg += "$name IP Address couldn't be resolved to hostname`n" + $errMsg += "IP Address couldn't be resolved to hostname`n" } } Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM Serial Number lookup' -PercentComplete 30 -ParentId 1 @@ -33,7 +33,7 @@ function Get-Hostname ([string]$name) { if ($res) { Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1 return $res,'' - } else { $errMsg += "$name Service Tag not found in SCCM`n"} + } else { $errMsg += "Service Tag not found in SCCM`n"} } Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM MAC Address lookup' -PercentComplete 40 -ParentId 1 # Regex to match MAC Address brought to you by https://stackoverflow.com/a/4260512 @@ -42,7 +42,7 @@ function Get-Hostname ([string]$name) { if ($res) { Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1 return $res,'' - } else { $errMsg += "$name MAC Address not found in SCCM`n"} + } else { $errMsg += "MAC Address not found in SCCM`n"} } # Last resort checks diff --git a/Get-PC/Private/PCLocal.ps1 b/Get-PC/Private/PCLocal.ps1 index 0b36e53..b8c36c6 100644 --- a/Get-PC/Private/PCLocal.ps1 +++ b/Get-PC/Private/PCLocal.ps1 @@ -44,13 +44,13 @@ #MAC Address - $MAC = ($win32_networkadapterconfiguration | Where-Object {$_.IpEnabled -Match "True"} | Select-Object -Expand macaddress) -join "," + $MAC = ($win32_networkadapterconfiguration | Where-Object {$_.IpEnabled -Match "True"} | Select-Object -Expand macaddress) -join " , " #IP $ip = ($win32_networkadapterconfiguration | Where-Object {$_.IpEnabled -Match "True"} | Select-Object -Expand IPAddress | # IPv4 address filter Where-Object {$_ -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$"} - ) -join "," + ) -join " , " <# if($ip -is [array]){ $ip = $ip[0] diff --git a/Get-PC/Private/ScanToEmail.ps1 b/Get-PC/Private/ScanToEmail.ps1 deleted file mode 100644 index da5b876..0000000 --- a/Get-PC/Private/ScanToEmail.ps1 +++ /dev/null @@ -1,165 +0,0 @@ -# Many printers only have self-signed ssl certs. This type is used to -# disable the ssl checking (basically clicking "Proceed to unsecure website") -if (-not ([System.Management.Automation.PSTypeName]'TrustAllCertsPolicy').Type) { - add-type @" -using System.Net; -using System.Security.Cryptography.X509Certificates; -public class TrustAllCertsPolicy : ICertificatePolicy { - public bool CheckValidationResult( - ServicePoint srvPoint, X509Certificate certificate, - WebRequest request, int certificateProblem) { - return true; -} -} -"@ -} - -function ScanToEmail { - param ( - [string]$printer - ) - - $DNSServers = [ordered]@{ - 'Sam Square/Walnut' = @{ - 'Primary' = '10.98.2.45' - 'Secondary' = '10.98.2.74' - } - 'AGH' = @{ - 'Primary' = '10.10.15.11' - 'Secondary' = '10.30.15.18' - } - 'SPCH' = @{ - 'Primary' = '10.50.15.25' - 'Secondary' = '10.60.15.14' - } - 'GSRMC' = @{ - 'Primary' = '10.20.15.16' - 'Secondary' = '10.98.2.74' - } - 'SLCH' = @{ - 'Primary' = '10.30.15.18' - 'Secondary' = '10.10.15.11' - } - 'SNLH' = @{ - 'Primary' = '10.60.15.14' - 'Secondary' = '10.50.15.25' - } - } - - $SMTPServer = "shssmtp01.int.samhealth.net" - - <# - Typically SNMP is set to read-only on most printers so we'll have to - replicate web requests. There isn't really a standard so this support - will have to be added for each new scheme. We can determine which scheme - to use based on the model number - #> - $snmp = New-Object -ComObject olePrn.OleSNMP - $printerip = (Resolve-DnsName $printer).IPAddress - $snmp.open($printerip, 'public', 2, 3000) - try { $model = $snmp.Get('.1.3.6.1.2.1.25.3.2.1.3.1') } catch { $model = $null } - $ModelSetupFunction = switch -Regex ($model) { - '^HP LaserJet MFP M5\d\d' { $function:ScanToEmailHPFutureSmart } - '^HP LaserJet MFP M6\d\d' { $function:ScanToEmailHPFutureSmart } - default { $null } - } - if ($null -eq $ModelSetupFunction) { - Write-Host -ForegroundColor Yellow "Printer model $model not supported at this time. Manual configuration required." - return - } - for ($i = 0; $i -lt $DNSServers.Count; $i++) { - Write-Host "[$i] $($DNSServers[$i])" - } - [int]$site = Read-Host "Select site: " - if ($null -eq $site) { - Write-Host -ForegroundColor Yellow "Unsupported site selected" - return - } - & $ModelSetupFunction $printer.DomainName $DNSServers.$site -} - -# hp 400 series mfps -Function ScanToEmailHPLJM400 { - param ( - [string]$PrinterDomainName, - $DNSServers - ) - # No server certificate so overwrite checking - [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} - Invoke-WebRequest "https://$PrinterDomainName/IoMgmt/Adapters/Eth0/Profiles/Active" -Method PUT -Body @" - - - - - - $($DNSServers.Primary) - - - $($DNSServers.Secondary) - - - - -"@ -ContentType 'text/xml' -} - -# HP printers with Future Smart firmware -# Developed for HP FutureSmart 5 -# Tested on -# 5.4 -Function ScanToEmailHPFutureSmart { - param ( - [string]$PrinterDomainName, - $DNSServers - ) - $printerName = if ($PrinterDomainName -match '^[^.]*(?=\.)') { $Matches[0] } - $printerEmail = "$printerName@samhealth.org" - - # No server certificate so overwrite checking - $savePolicy = [System.Net.ServicePointManager]::CertificatePolicy - [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy - - $res = Invoke-WebRequest "https://$PrinterDomainName/network_id.htm" -Method GET -SessionVariable WebSession - if ($res.Content -match 'id="CSRFToken".*VALUE="(.+)"') { $CSRFToken = [uri]::EscapeDataString($Matches[1]) } - - Invoke-WebRequest "https://$PrinterDomainName/network_id.htm/config" ` - -Method POST ` - -WebSession $WebSession ` - -ContentType 'application/x-www-form-urlencoded' ` - -Body "IPv4_DnsServerId=$($DNSServers.Primary)&IPv4_Sec_DnsServerId=$($DNSServers.Secondary)&Apply=Apply&CSRFToken=$CSRFToken" - - #New csrf token? - #$res = Invoke-WebRequest "https://$PrinterDomainName/hp/device/BasicSend/Index" -Method GET -SessionVariable WebSession - #if ($res.Content -match 'id="CSRFToken".*VALUE="(.+)"') { $CSRFToken = [uri]::EscapeDataString($Matches[1]) } - - # Enable smtp and set email - Invoke-WebRequest "https://$PrinterDomainName/hp/device/BasicSend/Save" ` - -Method POST ` - -WebSession $WebSession ` - -ContentType 'application/x-www-form-urlencoded' ` - -Body "FilterUsage=SendToEmail&EmailFromAddress=$printerEmail&FormButtonSubmit=Apply&CSRFToken=$CSRFToken" - - # Set smtp server - Invoke-WebRequest "https://$PrinterDomainName/hp/device/SmtpWizard/Save" ` - -Method POST ` - -WebSession $WebSession ` - -ContentType 'application/x-www-form-urlencoded' ` - -Body "FilterUsage=SendToEmail&StepId=4&SmtpSelection=1&SmtpServerName=$SMTPServer&SmtpServerPort=25&SmtpSplitEmail=0&FormButtonSubmit=Next&CSRFToken=$CSRFToken" - - # Set authentication (none) - Invoke-WebRequest "https://$PrinterDomainName/hp/device/SmtpWizard/Save" ` - -Method POST ` - -WebSession $WebSession ` - -ContentType 'application/x-www-form-urlencoded' ` - -Body "FilterUsage=SendToEmail&StepId=5&SmtpAuthentication=False&FormButtonSubmit=Next&CSRFToken=$CSRFToken" - - # Set usage (just scan to email) - Invoke-WebRequest "https://$PrinterDomainName/hp/device/SmtpWizard/Save" ` - -Method POST ` - -WebSession $WebSession ` - -ContentType 'application/x-www-form-urlencoded' ` - -Body "FilterUsage=SendToEmail&StepId=6&SmtpUsage=SendToEmail&FormButtonSubmit=Next&CSRFToken=$CSRFToken" - - - [System.Net.ServicePointManager]::CertificatePolicy = $savePolicy -} \ No newline at end of file diff --git a/Get-PC/Public/Get-PC.ps1 b/Get-PC/Public/Get-PC.ps1 index 9910f48..6ebe2be 100644 --- a/Get-PC/Public/Get-PC.ps1 +++ b/Get-PC/Public/Get-PC.ps1 @@ -61,6 +61,7 @@ Function Get-PC { -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 + -CMDBWeb | opens the CMDB page for the computer -Devices | shows connected monitors and usb devices -DevicesUnplugged | shows unplugged devices like scanners and printers -Enable | re-enable computer account in AD @@ -77,6 +78,7 @@ Function Get-PC { -PCCleanup | removes temp files and inactive user profiles -PCReboot | reboots computer -PCRename | renames computer + -Quiet | used in conjuction with remote viewer will remove green bar -RemoteDesktopApp | remote into computer using RDP -ResetRepository | remotely resets repository -Resources | more details about system resources diff --git a/Get-PC/patchnotes.txt b/Get-PC/patchnotes.txt index b753f5d..c069389 100644 --- a/Get-PC/patchnotes.txt +++ b/Get-PC/patchnotes.txt @@ -1,4 +1,4 @@ -Path: +Path: 2024-10-24 -Fix Enable flag also removes workstation from Disabled Computers group -Update Orion url -Perf. Devices and Unplugged Devices are now 70% faster!