Created
September 11, 2021 15:41
-
-
Save tonylea/0d181eca8e0d5d12e9fb1863e3cf69ae to your computer and use it in GitHub Desktop.
Validate file extension in PowerShell parameter
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
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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: Validating file and folder paths in PowerShell parameters