Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Created September 1, 2019 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlagueHO/6cd2cf662c57a7ef12e5e1da946b5272 to your computer and use it in GitHub Desktop.
Save PlagueHO/6cd2cf662c57a7ef12e5e1da946b5272 to your computer and use it in GitHub Desktop.
Invoke an action on a file using a swtich statement of actions
$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