Skip to content

Instantly share code, notes, and snippets.

@tonylea
Created September 11, 2021 15:41
Show Gist options
  • Save tonylea/0d181eca8e0d5d12e9fb1863e3cf69ae to your computer and use it in GitHub Desktop.
Save tonylea/0d181eca8e0d5d12e9fb1863e3cf69ae to your computer and use it in GitHub Desktop.
Validate file extension in PowerShell parameter
param (
[ValidateScript({
if (-Not ($_ | Test-Path) ) { throw "File does not exist" }
if (-Not ($_ | Test-Path -PathType Leaf) ) { throw "The Path argument must be a file. Folder paths are not allowed." }
if ($_ -notmatch "\.tfplan$") { throw "The file specified in the path argument must be type tfplan" }
return $true
})]
[System.IO.FileInfo]
$FilePath
)
@tonylea
Copy link
Author

tonylea commented Sep 11, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment