Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Readability – Using Continue instead of ElseIf

I found the following more readable, opposed to trying to parse out if/elseif. What are your thoughts about this ? Is there a better way ?

Example code where I want to check a bunch of things about an EXE on a remote system before replacing it with a different version:

# Testing Section - Reachable? Already done? Process Running? Folder RW? etc.
    If ($true) {
        $ProcessList = Get-Process -ComputerName $PCname -ErrorAction SilentlyContinue 
        if ($null -eq $ProcessList) {
            Log -Msg "Error - Get process list from host failed, Host down? Skipping." -PCname $PCName
            $Failed += $PCName
            Continue
        }
        $Process = $ProcessList | Where-Object { $_.ProcessName -match "SOMEPRSS$" }
        if ($SearchPss -eq [string]($Process.ProcessName)) {
            Log -Msg "Error - Process is still running. Skipping." -PCname $PCName
            $Failed += $PCName
            Continue
        }
        If (-Not (Test-RemoteFolderReadWrite -Path $RemoteFolderPath)) {
            Log -Msg "Error - Unable to Read/Write to remote filesystem. Skipping" -PCname $PCName
            $Failed += $PCName
            Continue
        }
        if (Test-FileLock -Path $RemoteFilePath) {
            Log -Msg "Error - Lock on remote file. Skipping." -PCname $PCName
            $Failed += $PCName
            Continue
        }
    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think this is answered better at https://codereview.stackexchange.com/
Comments sum up this topic is eye of the beholder.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading