From 2a6b59c0f9c8bcf5690ad370a845fddd145f85a1 Mon Sep 17 00:00:00 2001 From: Hare Sudhan Date: Sun, 14 Apr 2024 17:38:11 -0400 Subject: [PATCH] fix linting issues --- Public/AtomicRunnerService.ps1 | 20 ++++++++++---------- Public/Invoke-AtomicRunner.ps1 | 2 +- Public/Invoke-KickoffAtomicRunner.ps1 | 2 +- Public/Invoke-SetupAtomicRunner.ps1 | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Public/AtomicRunnerService.ps1 b/Public/AtomicRunnerService.ps1 index 8d7e59a..9530d2a 100644 --- a/Public/AtomicRunnerService.ps1 +++ b/Public/AtomicRunnerService.ps1 @@ -237,13 +237,13 @@ Param( [Parameter(ParameterSetName='Setup', Mandatory=$true)] [String]$UserName, # Set the service to run as this user - + [Parameter(ParameterSetName='Setup', Mandatory=$false)] - [String]$Password, # Use this password for the user + [SecureString]$Password, # Use this password for the user [Parameter(ParameterSetName='Setup', Mandatory=$false)] [String]$installDir= "${ENV:windir}\System32", # Where to install the service files - + [Parameter(ParameterSetName='Setup2', Mandatory=$false)] [System.Management.Automation.PSCredential]$Credential, # Service account credential @@ -331,7 +331,7 @@ Function Now { $ms = $true $nsSuffix = "000" } - } + } if ($ms) { $now += ".{0:000}$nsSuffix" -f $Date.MilliSecond } @@ -399,7 +399,7 @@ Function Get-PSThread () { [Parameter(Mandatory=$false, ValueFromPipeline=$true, Position=0)] [int[]]$Id = $PSThreadList.Keys # List of thread IDs ) - $Id | % { $PSThreadList.$_ } + $Id | ForEach-Object { $PSThreadList.$_ } } Function Start-PSThread () { @@ -441,7 +441,7 @@ Function Start-PSThread () { $PSPipeline = [powershell]::Create() $PSPipeline.Runspace = $RunSpace $PSPipeline.AddScript($ScriptBlock) | Out-Null - $Arguments | % { + $Arguments | ForEach-Object { Write-Debug "Adding argument [$($_.GetType())]'$_'" $PSPipeline.AddArgument($_) | Out-Null } @@ -764,7 +764,7 @@ $source = @" AutoLog = true; eventLog = new System.Diagnostics.EventLog(); // EVENT LOG [ - if (!System.Diagnostics.EventLog.SourceExists(ServiceName)) { + if (!System.Diagnostics.EventLog.SourceExists(ServiceName)) { System.Diagnostics.EventLog.CreateEventSource(ServiceName, "$logName"); } eventLog.Source = ServiceName; @@ -807,7 +807,7 @@ $source = @" Win32Exception w32ex = e as Win32Exception; // Try getting the WIN32 error code if (w32ex == null) { // Not a Win32 exception, but maybe the inner one is... w32ex = e.InnerException as Win32Exception; - } + } if (w32ex != null) { // Report the actual WIN32 error serviceStatus.dwWin32ExitCode = w32ex.NativeErrorCode; } else { // Make up a reasonable reason @@ -845,7 +845,7 @@ $source = @" Win32Exception w32ex = e as Win32Exception; // Try getting the WIN32 error code if (w32ex == null) { // Not a Win32 exception, but maybe the inner one is... w32ex = e.InnerException as Win32Exception; - } + } if (w32ex != null) { // Report the actual WIN32 error serviceStatus.dwWin32ExitCode = w32ex.NativeErrorCode; } else { // Make up a reasonable reason @@ -977,7 +977,7 @@ if ($Setup) { # Install the service Write-Debug "Installation is necessary" # Also avoids a ScriptAnalyzer warning # And continue with the installation. } - if (!(Test-Path $installDir)) { + if (!(Test-Path $installDir)) { New-Item -ItemType directory -Path $installDir | Out-Null } # Copy the service script into the installation directory diff --git a/Public/Invoke-AtomicRunner.ps1 b/Public/Invoke-AtomicRunner.ps1 index 3bac585..4324491 100755 --- a/Public/Invoke-AtomicRunner.ps1 +++ b/Public/Invoke-AtomicRunner.ps1 @@ -189,7 +189,7 @@ function Invoke-AtomicRunner { # Perform cleanup, Showdetails or Prereq stuff for all scheduled items and then exit if ($Cleanup -or $ShowDetails -or $CheckPrereqs -or $ShowDetailsBrief -or $GetPrereqs -or $listOfAtomics) { $schedule | ForEach-Object { - Invoke-AtomicTestFromScheduleRow $_ + Invoke-AtomicTestFromScheduleRow $_ } return } diff --git a/Public/Invoke-KickoffAtomicRunner.ps1 b/Public/Invoke-KickoffAtomicRunner.ps1 index 94bb0ef..7f79e07 100644 --- a/Public/Invoke-KickoffAtomicRunner.ps1 +++ b/Public/Invoke-KickoffAtomicRunner.ps1 @@ -46,7 +46,7 @@ function Invoke-KickoffAtomicRunner { if ($artConfig.debug) { $Arguments = "-Command Invoke-AtomicRunner *>> $all_log_file" } else { $Arguments = "-Command Invoke-AtomicRunner" } # Invoke the atomic as its own process because we don't want to skip the cleanup and rename process in the event that AV kills the process running the atomic $p1 = Start-Process -FilePath $FileName -ArgumentList $Arguments -WorkingDirectory $WorkingDirectory -PassThru - + if ($artConfig.debug) { $Arguments = "-Command Invoke-AtomicRunner -scheduledTaskCleanup *>> $all_log_file_cleanup" } else { $Arguments = "-Command Invoke-AtomicRunner -scheduledTaskCleanup" } $p2 = Start-Process -FilePath $FileName -ArgumentList $Arguments -WorkingDirectory $WorkingDirectory -PassThru diff --git a/Public/Invoke-SetupAtomicRunner.ps1 b/Public/Invoke-SetupAtomicRunner.ps1 index 8cf7cbf..9eac4ae 100755 --- a/Public/Invoke-SetupAtomicRunner.ps1 +++ b/Public/Invoke-SetupAtomicRunner.ps1 @@ -7,7 +7,7 @@ function Invoke-SetupAtomicRunner { Param( [Parameter(Mandatory = $false)] [switch] - $SkipServiceSetup + $SkipServiceSetup ) # ensure running with admin privs @@ -50,7 +50,7 @@ function Invoke-SetupAtomicRunner { $time2 = 600000 # 10 minutes in miliseconds $actionLast = "restart" $timeLast = 3600000 # 1 hour in miliseconds - $resetCounter = 86400 # 1 day in seconds + $resetCounter = 86400 # 1 day in seconds $services = Get-CimInstance -ClassName 'Win32_Service' | Where-Object { $_.DisplayName -imatch $ServiceDisplayName } $action = $action1 + "/" + $time1 + "/" + $action2 + "/" + $time2 + "/" + $actionLast + "/" + $timeLast foreach ($service in $services) { @@ -137,14 +137,14 @@ function Add-EnvPath { $persistedPaths = [Environment]::GetEnvironmentVariable('Path', $containerType) -split ';' if ($persistedPaths -notcontains $Path) { - $persistedPaths = $persistedPaths + $Path | where { $_ } + $persistedPaths = $persistedPaths + $Path | Where-Object { $_ } [Environment]::SetEnvironmentVariable('Path', $persistedPaths -join ';', $containerType) } } $envPaths = $env:Path -split ';' if ($envPaths -notcontains $Path) { - $envPaths = $envPaths + $Path | where { $_ } + $envPaths = $envPaths + $Path | Where-Object { $_ } $env:Path = $envPaths -join ';' } } \ No newline at end of file