Invoke an action on a file using a swtich statement of actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$VerbosePreference = 'Continue' | |
$action = 'New' | |
$path = 'c:\somefile.txt' | |
$result = switch ($action) { | |
'New' { | |
Write-Verbose -Message 'Execute New-Item' | |
New-Item -Path $path | |
break | |
} | |
'Remove' { | |
Write-Verbose -Message 'Execute Remove-Item' | |
Remove-Item -Path $path | |
break | |
} | |
'Get' { | |
Write-Verbose -Message 'Execute Get-Item' | |
Get-Item -Path $path | |
break | |
} | |
Default { | |
Write-Verbose -Message 'Invalid Action' | |
} | |
} | |
return $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment