I can get Add-Type -Path c:\scripts\validateMatches.vb to work with the script below but trying to reference the compiled version fails. This script just adds a [ValidateMatches] type and is identical to [ValidatePattern] but with the extra message parameter. This was converted to VB.NET from the C# source first published at www.huddledmasses.org/jaykul/.The Test-Backup script is as follows:
function Test-Folder {
param([ValidateMatches(Options='None',
Pattern='^[a-z]:\\.*[^*\\]$',
Message="Please enter a valid path like: 'c:\Modules\library'")]
[string[]]$folder = $pwd
)
write-host $folder -fore cyan
}
Test-Folder 'd:\scripts\modules','C:\users\fred' #Use Upper case C here to trigger error.
The Option='None' is identical to that in [ValidatePattern], poorly documented at Microsoft, and just forces Case Respect. If I try and reference the compiled dll the following error is generated:
.\Test-Backup
Cannot find the type for custom attribute 'ValidateMatches'. Make sure that the assembly that contains this type is loaded.
At c:\Scripts\test-backup.ps1:7 char:18
+ [String[]][ValidateMatches(Pattern='^[a-z]:\\.*[^*\\]$',
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ([ValidateMatche...les\library'")]:AttributeAst) [], RuntimeException
+ FullyQualifiedErrorId : CustomAttributeTypeNotFound
So what simple setting is missing please?
↧
Add-Type -Path c:\scripts\validateMatches.dll failing.
↧