Skip to content

Commit

Permalink
Verbose logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrodksmith authored Mar 11, 2024
1 parent c3bcf8e commit 05555af
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 15 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

## [Unreleased]

# [1.0.1] - 11-03-2024

### Added

- Minor Verbose logging

### Changed

- Modules now check for specific version

### Deprecated

### Removed

### Fixed

# [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
12 changes: 6 additions & 6 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
$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
Install-Module RunAsUser -Force -RequiredVersion '2.4.0'
}
Import-Module RunAsUser -Force
}
Import-Module RunAsUser -Force -Version '2.4.0'
}
6 changes: 3 additions & 3 deletions Private/Helpers/Get-SeleniumModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function Get-SeleniumModule {

}
Import-Module PowerShellGet
$seleniumModule = Get-Module -Name Selenium -ListAvailable
$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
Install-Module Selenium -Force -RequiredVersion '3.0.1'
}
Import-Module Selenium -Force
Import-Module Selenium -Force -Version '3.0.1'
}
10 changes: 7 additions & 3 deletions Private/Helpers/Get-WebDriver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ 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
Expand All @@ -122,7 +122,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 @@ -147,7 +147,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
5 changes: 5 additions & 0 deletions Private/Helpers/Start-SeleniumModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,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 @@ -65,6 +69,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
2 changes: 2 additions & 0 deletions Private/Helpers/Stop-SeleniumModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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 @@ -45,6 +46,7 @@ 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 {

Expand Down
3 changes: 2 additions & 1 deletion Public/Get-WarrantyAsus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function Get-WarrantyAsus {
try{
$driver = Start-SeleniumModule -WebDriver $Seleniumdrivermode -Headless $true
}catch{
Write-Verbose $_.Exception.Message
$WarObj = [PSCustomObject]@{
'Serial' = $Serial
'Warranty Product name' = $null
Expand All @@ -79,7 +80,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
1 change: 1 addition & 0 deletions Public/Get-WarrantyDell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function Get-WarrantyDell {
try{
$driver = Start-SeleniumModule -WebDriver $Seleniumdrivermode -Headless $true
}catch{
Write-Verbose $_.Exception.Message
$WarObj = [PSCustomObject]@{
'Serial' = $Serial
'Warranty Product name' = $null
Expand Down
2 changes: 1 addition & 1 deletion Public/Get-WarrantyEdsys.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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
1 change: 1 addition & 0 deletions Public/Get-WarrantyHP.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 Down

0 comments on commit 05555af

Please sign in to comment.