Skip to content

Commit

Permalink
Merge pull request #6 from jayrodksmith/dev-edge
Browse files Browse the repository at this point in the history
1.0.1 Release
  • Loading branch information
jayrodksmith authored Mar 11, 2024
2 parents 4451081 + b8e2015 commit 0478b92
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 69 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

## [Unreleased]

# [1.0.1] - 11-03-2024

### Added

- Minor Verbose logging

### Changed

- Modules now check for specific version

### Deprecated

### Removed

### Fixed

- Chrome Bug

# [1.0.0] - 10-03-2024

### Added
Expand Down
2 changes: 1 addition & 1 deletion EasyWarrantyCheck.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'EasyWarrantyCheck.psm1'

# Version number of this module.
ModuleVersion = '1.0.0'
ModuleVersion = '1.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
85 changes: 51 additions & 34 deletions EasyWarrantyCheck_RMM.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function Get-Warranty {

# Web Driver mode, Edge or Chrome ( Edge Beta Support )
[Parameter(Mandatory = $false, ParameterSetName = 'Default')]
[Parameter(Mandatory = $false, ParameterSetName = 'CentralNinja')]
[ValidateSet('Chrome', 'Edge')]
[String]$Seleniumdrivermode = 'Chrome',

Expand All @@ -36,7 +37,7 @@ function Get-Warranty {
# Enable Registry Storing
[Parameter(Mandatory = $false, ParameterSetName = 'Default')]
[bool]$EnableRegistry = $true,

# Registry Path
[Parameter(Mandatory = $false, ParameterSetName = 'Default')]
[String]$RegistryPath = 'HKLM:\SOFTWARE\RMMCustomInfo\',
Expand All @@ -46,6 +47,7 @@ function Get-Warranty {
[bool]$ForceUpdate = $false,

# Custom Machine Details, available in both sets
[Parameter(Mandatory = $false, ParameterSetName = 'Default')]
[Parameter(Mandatory = $false, ParameterSetName = 'CentralNinja')]
[String]$Serial = 'Automatic',

Expand Down Expand Up @@ -252,13 +254,14 @@ function Get-WarrantyAsus {
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium
Remove-Module Selenium -Verbose:$false
return $warObj
}
# Start a new browser session with headless mode
try{
$driver = Start-SeleniumModule -WebDriver $Seleniumdrivermode -Headless $true
}catch{
Write-Verbose $_.Exception.Message
$WarObj = [PSCustomObject]@{
'Serial' = $Serial
'Warranty Product name' = $null
Expand All @@ -269,7 +272,7 @@ function Get-WarrantyAsus {
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium
Remove-Module Selenium -Verbose:$false
return $warObj
}
# Navigate to the warranty check URL
Expand All @@ -284,7 +287,7 @@ function Get-WarrantyAsus {
$submitcheckcookiesButton = $driver.FindElementByXPath("//div[@class='btn-asus btn-ok btn-read-ck' and @aria-label='Accept']")
$submitcheckcookiesButton.Click()
} catch{

Write-Verbose $_.Exception.Message
}
$checkPrivacyButton = $driver.FindElementById("checkPrivacy")
$checkPrivacyButton.Click()
Expand Down Expand Up @@ -401,13 +404,14 @@ function Get-WarrantyDell {
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium
Remove-Module Selenium -Verbose:$false
return $warObj
}
# Start a new browser session with headless mode
try{
$driver = Start-SeleniumModule -WebDriver $Seleniumdrivermode -Headless $true
}catch{
Write-Verbose $_.Exception.Message
$WarObj = [PSCustomObject]@{
'Serial' = $Serial
'Warranty Product name' = $null
Expand All @@ -418,7 +422,7 @@ function Get-WarrantyDell {
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium
Remove-Module Selenium -Verbose:$false
return $warObj
}
# Navigate to the warranty check URL
Expand Down Expand Up @@ -526,7 +530,7 @@ function Get-WarrantyEdsys {
try {
$response = Invoke-WebRequest -Uri $url -Method Post -Body $payload -ContentType "application/x-www-form-urlencoded" -UseBasicParsing
}catch{
Write-Host $($_.Exception.Message)
Write-Verbose $_.Exception.Message
}
if($response){
# Output the response
Expand Down Expand Up @@ -677,6 +681,7 @@ function Get-WarrantyHP {
}
catch {
if ($PSCmdlet.ParameterSetName -eq 'Default') {
Write-Verbose $_.Exception.Message
Write-Host "###########################"
Write-Host "WARNING"
Write-Host "$($browserinstalled.software) not detected"
Expand All @@ -700,7 +705,7 @@ function Get-WarrantyHP {
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium
Remove-Module Selenium -Verbose:$false
return $warObj
}
catch {
Expand All @@ -715,7 +720,7 @@ function Get-WarrantyHP {
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium
Remove-Module Selenium -Verbose:$false
return $warObj
}
}
Expand All @@ -741,13 +746,13 @@ function Get-WarrantyHP {
$errorMsgElement = $driver.FindElementByClassName("errorTxt")
}
catch {
Write-Debug "No Product Model required"
Write-Verbose "No Product Model required"
}

if ($null -ne $errorMsgElement -and $null -ne $SystemSKU) {
# Error message found
Write-Host "Using SystemSKU input"
Write-Debug "Need Product ID"
Write-Verbose "Need Product ID"
$productField = $driver.FindElementById("product-number inputtextPN")
$productField.SendKeys($SystemSKU)
$submitButton = $driver.FindElementById("FindMyProductNumber")
Expand All @@ -761,7 +766,7 @@ function Get-WarrantyHP {
elseif ($null -ne $errorMsgElement -and $global:ServerMode -ne $true) {
# Error message found
Write-Host "Searching for additional SystemSKU......."
Write-Debug "Need Product ID"
Write-Verbose "Need Product ID"
# Define the registry path
$regPath = "HKLM:\HARDWARE\DESCRIPTION\System\BIOS"
# Get the value of "SystemSKU" if it exists
Expand Down Expand Up @@ -1237,18 +1242,19 @@ function Get-RunAsUserModule {
#>
try {
Set-ExecutionPolicy Bypass -scope Process -Force -ErrorAction SilentlyContinue | Out-Null
}catch{
Set-ExecutionPolicy Bypass -Scope Process -Force -ErrorAction SilentlyContinue | Out-Null
} catch {

}
Import-Module PowerShellGet
$RunAsUser = Get-Module -Name RunAsUser -ListAvailable
Import-Module PowerShellGet -Verbose:$false
$RunAsUser = Get-Module -Name RunAsUser -ListAvailable | Where-Object { $_.Version -eq '2.4.0' }
if (-not $RunAsUser) {
Get-PackageProvider -Name "nuGet" -ForceBootstrap | Out-Null
Install-Module RunAsUser -Force
Get-PackageProvider -Name "nuGet" -ForceBootstrap -Verbose:$false | Out-Null
Install-Module RunAsUser -Force -RequiredVersion '2.4.0' -Verbose:$false
}
Import-Module RunAsUser -Force
}
Import-Module RunAsUser -Force -Version '2.4.0' -Verbose:$false
}


function Get-SeleniumModule {
<#
Expand All @@ -1267,13 +1273,13 @@ function Get-SeleniumModule {
}catch{

}
Import-Module PowerShellGet
$seleniumModule = Get-Module -Name Selenium -ListAvailable
Import-Module PowerShellGet -Verbose:$false
$seleniumModule = Get-Module -Name Selenium -ListAvailable | Where-Object { $_.Version -eq '3.0.1' }
if (-not $seleniumModule) {
Get-PackageProvider -Name "nuGet" -ForceBootstrap | Out-Null
Install-Module Selenium -Force
Get-PackageProvider -Name "nuGet" -ForceBootstrap -Verbose:$false | Out-Null
Install-Module Selenium -Force -RequiredVersion '3.0.1' -Verbose:$false
}
Import-Module Selenium -Force
Import-Module Selenium -Force -Version '3.0.1' -Verbose:$false
}

function Get-SeleniumModule4 {
Expand Down Expand Up @@ -1436,11 +1442,11 @@ function Get-WebDriver {
try {
Invoke-WebRequest $downloadLink -OutFile "$webDriversPath\chromeNewDriver.zip"
}catch{

Write-Verbose $_.Exception.Message
}
# Expand archive and replace the old file
Expand-Archive "$webDriversPath\chromeNewDriver.zip" -DestinationPath "$webDriversPath\tempchrome" -Force
Move-Item "$webDriversPath\tempchrome\chromedriver.exe" -Destination "$($webDriversPath)\chromedriver.exe" -Force
Move-Item "$webDriversPath\tempchrome\chromedriver-win64\chromedriver.exe" -Destination "$($webDriversPath)\chromedriver.exe" -Force

# clean-up
Remove-Item "$webDriversPath\chromeNewDriver.zip" -Force | Out-Null
Expand All @@ -1452,7 +1458,7 @@ function Get-WebDriver {
try {
$edgeVersion = (Get-Item (Get-ItemProperty $edgeRegistryPath).'(Default)').VersionInfo.ProductVersion
} catch {

Write-Verbose $_.Exception.Message
}
# check which driver versions are installed
$edgeDriverVersion = Get-LocalDriverVersion -pathToDriver $edgeDriverPath
Expand All @@ -1477,7 +1483,11 @@ function Get-WebDriver {
}

# download the file
Invoke-WebRequest $downloadLink -OutFile "$webDriversPath\edgeNewDriver.zip"
try {
Invoke-WebRequest $downloadLink -OutFile "$webDriversPath\edgeNewDriver.zip"
} catch{
Write-Verbose $_.Exception.Message
}

# epand archive and replace the old file
Expand-Archive "$webDriversPath\edgeNewDriver.zip" -DestinationPath "$webDriversPath\tempedge" -Force
Expand Down Expand Up @@ -1516,7 +1526,7 @@ function Start-SeleniumModule {
)
if($WebDriver -eq "Edge"){
Get-RunAsUserModule
Import-Module -Name RunAsUser
Import-Module -Name RunAsUser -Verbose:$false
$scriptblock = {
Import-Module Selenium
$WebDriverPath = "C:\temp\EasyWarrantyCheck\WebDrivers"
Expand All @@ -1535,14 +1545,18 @@ function Start-SeleniumModule {
) })
$driver = New-Object OpenQA.Selenium.Edge.EdgeDriver($EdgeService, $edgeOptions)
Start-Sleep -Seconds 3
return $driver
}
$invokeasuser = invoke-ascurrentuser -scriptblock $scriptblock -UseWindowsPowerShell -CaptureOutput
Write-Verbose "Driver Invoked : $invokeasuser"
$process = "msedgedriver.exe"
$commandLine = Get-CimInstance Win32_Process -Filter "name = '$process'" | select CommandLine
Write-Verbose "msedgedriver.exe process : $commandLine"
# Regular expression pattern to match port number
$portPattern = '--port=(\d+)'
if ($commandLine -match $portPattern) {
$driverportnumber = $matches[1]
Write-Verbose "Driver Port Number : $driverportnumber"
} else {
Write-Output "Port number not found."
}
Expand All @@ -1557,6 +1571,7 @@ function Start-SeleniumModule {
"debuggerAddress" = $debuggerAddress
})
# Connect to the existing Edge session

return $driver = New-Object OpenQA.Selenium.Remote.RemoteWebDriver($remoteAddress, $options)
}
if($WebDriver -eq "Chrome"){
Expand Down Expand Up @@ -1606,6 +1621,7 @@ function Stop-SeleniumModule {
foreach ($process in $headlessEdgeProcesses) {
$processID = $process.ProcessId
if ($processID -ne $null) {
Write-Verbose "Stopping : $processID"
Stop-Process -Id $processID -Force -ErrorAction SilentlyContinue | Out-null
} else {
}
Expand All @@ -1618,16 +1634,17 @@ function Stop-SeleniumModule {
foreach ($process in $driverProcesses) {
$processID = $process.ProcessId
if ($processID -ne $null) {
Write-Verbose "Stopping : $processID"
Stop-Process -Id $processID -Force -ErrorAction SilentlyContinue | Out-null
} else {

}
}
Remove-Module Selenium -Force -ErrorAction SilentlyContinue | Out-null
Remove-Module Selenium -Force -ErrorAction SilentlyContinue -Verbose:$false | Out-null
}
if($WebDriver -eq "Chrome"){
$driver.quit()
Remove-Module Selenium -Force -ErrorAction SilentlyContinue | Out-null
Remove-Module Selenium -Force -ErrorAction SilentlyContinue -Verbose:$false | Out-null
}
}

Expand Down Expand Up @@ -1722,9 +1739,9 @@ function Write-WarrantyRegistry{
if (-not (Test-Path $RegistryPath)) {
# Create the registry key if it doesn't exist
New-Item -Path $RegistryPath -Force -ErrorAction SilentlyContinue | Out-Null
Write-Debug "Registry key created successfully."
Write-Verbose "Registry key created successfully."
} else {
Write-Debug "Registry key already exists."
Write-Verbose "Registry key already exists."
}
if($Warrantystart){
New-ItemProperty -Path $RegistryPath -Name "WarrantyStart" -PropertyType String -Value $Warrantystart -Force -ErrorAction SilentlyContinue | Out-Null
Expand Down
16 changes: 8 additions & 8 deletions Private/Helpers/Get-RunAsUserModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ function Get-RunAsUserModule {
#>
try {
Set-ExecutionPolicy Bypass -scope Process -Force -ErrorAction SilentlyContinue | Out-Null
}catch{
Set-ExecutionPolicy Bypass -Scope Process -Force -ErrorAction SilentlyContinue | Out-Null
} catch {

}
Import-Module PowerShellGet
$RunAsUser = Get-Module -Name RunAsUser -ListAvailable
Import-Module PowerShellGet -Verbose:$false
$RunAsUser = Get-Module -Name RunAsUser -ListAvailable | Where-Object { $_.Version -eq '2.4.0' }
if (-not $RunAsUser) {
Get-PackageProvider -Name "nuGet" -ForceBootstrap | Out-Null
Install-Module RunAsUser -Force
Get-PackageProvider -Name "nuGet" -ForceBootstrap -Verbose:$false | Out-Null
Install-Module RunAsUser -Force -RequiredVersion '2.4.0' -Verbose:$false
}
Import-Module RunAsUser -Force
}
Import-Module RunAsUser -Force -Version '2.4.0' -Verbose:$false
}
10 changes: 5 additions & 5 deletions Private/Helpers/Get-SeleniumModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ function Get-SeleniumModule {
}catch{

}
Import-Module PowerShellGet
$seleniumModule = Get-Module -Name Selenium -ListAvailable
Import-Module PowerShellGet -Verbose:$false
$seleniumModule = Get-Module -Name Selenium -ListAvailable | Where-Object { $_.Version -eq '3.0.1' }
if (-not $seleniumModule) {
Get-PackageProvider -Name "nuGet" -ForceBootstrap | Out-Null
Install-Module Selenium -Force
Get-PackageProvider -Name "nuGet" -ForceBootstrap -Verbose:$false | Out-Null
Install-Module Selenium -Force -RequiredVersion '3.0.1' -Verbose:$false
}
Import-Module Selenium -Force
Import-Module Selenium -Force -Version '3.0.1' -Verbose:$false
}
Loading

0 comments on commit 0478b92

Please sign in to comment.