# ValidateScript parameter attribute messes with Splatted input?

**URL:** <https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936>\
**Category:** PowerShell Help\
**Created:** [July 6, 2018, 10:57am UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936 "2018-07-06T10:57:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sundmoon](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sundmoon](https://forums.powershell.org/u/sundmoon)\
**Post date:** [July 6, 2018, 10:57am UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/1 "2018-07-06T10:57:44Z")

</div>

```
function Convert-Wim2VHD {
  
  [CmdletBinding(SupportsShouldProcess = $true, 
    PositionalBinding = $false,
    ConfirmImpact = 'Medium')]
  Param
  (
    # Path to the new VHDX file (Must end in .vhdx)
    [Parameter(Position = 0, Mandatory = $true,
      HelpMessage = 'Enter the path for the new VHDX file')]
    [ValidateNotNullorEmpty()]
    [ValidatePattern(".\.vhdx?$")] **[ValidateScript( { if (Get-FullFilePath -Path $\_ | Split-Path | Resolve-Path ) { $true } else { Throw "Parent folder for $\_ does not exist." }** })]
```

**[ValidateScript( {  
if (Get-FullFilePath -Path $\_ |  
Split-Path |  
Resolve-Path ) {  
$true  
}  
else {  
Throw “Parent folder for $\_ does not exist.”  
}**

If I feed up this function with splatted input, I am getting error.  
Is this a feature or a bug, and how to deal with it?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [July 6, 2018, 11:03am UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/2 "2018-07-06T11:03:12Z")

</div>

What would the error be? Can you show an example of your splatted input? It’s a little tough to guess just by reading your code.

Parameter binding happens before validation, so there shouldn’t be any difference.

---

<div class="post-metadata">

**Author:** ![sundmoon](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sundmoon](https://forums.powershell.org/u/sundmoon)\
**Post date:** [July 6, 2018, 11:42am UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/3 "2018-07-06T11:42:07Z")

</div>

Thank you Don

I tried adding imgur picture link, but…

```
PS H:\DEV\HVLab> $ConvertWim2VHD_Param = @{
    Path = 'H:\DEV\HVLab\Images\W2016_CORE.vhdx'
    Index = 3 Size = 51GB DiskLayout = 'UEFI'
    Dynamic = $true SourcePath = 'H:\DEV\HVLab\Media\en_windows_server_2016_vl_x64_dvd_11636701.iso'
}

Convert-Wim2VHD @$ConvertWim2VHD_Param -verbose
```

```
Convert-Wim2VHD : Cannot validate argument on parameter 'Path'. Cannot bind argument to parameter 'Path' because it is an empty
string.
At line:10 char:17
+ Convert-Wim2VHD @$ConvertWim2VHD_Param -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Convert-Wim2VHD], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Convert-Wim2VHD
```

I am calling WindowsImageTools\Convert-Wim2VHD

> **[WindowsImageTools/WindowsImageTools at master · BladeFireLight/WindowsImageTools](https://github.com/BladeFireLight/WindowsImageTools/tree/master/WindowsImageTools)**
>
> master/WindowsImageTools

Name Value

* * *

PSVersion 5.1.17134.137

**I expand splatting, the error has gone**

---

<div class="post-metadata">

**Author:** ![sundmoon](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sundmoon](https://forums.powershell.org/u/sundmoon)\
**Post date:** [July 6, 2018, 12:52pm UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/4 "2018-07-06T12:52:19Z")

</div>

Thank you Don

SCREENSHOT ADDED

[[Album] imgur.com ![](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/2/2d89c51d3159ee648d8d73d7b007e748fa221892.jpeg "imgur.com") ](https://imgur.com/a/LzEjit3)

```
PS H:\DEV\HVLab> $ConvertWim2VHD_Param = @{
    Path = 'H:\DEV\HVLab\Images\W2016_CORE.vhdx'
    Index = 3 Size = 51GB DiskLayout = 'UEFI'
    Dynamic = $true SourcePath = 'H:\DEV\HVLab\Media\en_windows_server_2016_vl_x64_dvd_11636701.iso'
}

Convert-Wim2VHD @$ConvertWim2VHD_Param -verbose
```

```
Convert-Wim2VHD : Cannot validate argument on parameter 'Path'. Cannot bind argument to parameter 'Path' because it is an empty
string.
At line:10 char:17
+ Convert-Wim2VHD @$ConvertWim2VHD_Param -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Convert-Wim2VHD], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Convert-Wim2VHD
```

I am calling WindowsImageTools\Convert-Wim2VHD

> **[WindowsImageTools/WindowsImageTools at master · BladeFireLight/WindowsImageTools](https://github.com/BladeFireLight/WindowsImageTools/tree/master/WindowsImageTools)**
>
> master/WindowsImageTools

Name Value

* * *

PSVersion 5.1.17134.137

**I expand splatting, the error has gone**

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [July 6, 2018, 2:20pm UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/5 "2018-07-06T14:20:27Z")

</div>

You triggered our spam filters ;). When that happens, just chill - reposting again will get you locked out. We clear the filters every weekday.

You’re not constructing your hash table correctly, it looks like.

```
PS H:\DEV\HVLab> $ConvertWim2VHD_Param = @{
    Path = 'H:\DEV\HVLab\Images\W2016_CORE.vhdx'
    Index = 3
    Size = 51GB
    DiskLayout = 'UEFI'
    Dynamic = $true
    SourcePath = 'H:\DEV\HVLab\Media\en_windows_server_2016_vl_x64_dvd_11636701.iso'
}
```

It’s either one item per line, or you have to separate them all with semicolons. It’s the ValidateNotNullOrEmpty() that’s causing the error.

---

<div class="post-metadata">

**Author:** ![sundmoon](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sundmoon](https://forums.powershell.org/u/sundmoon)\
**Post date:** [July 6, 2018, 4:24pm UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/6 "2018-07-06T16:24:18Z")

</div>

Of course I had formatted the hashtable properly: I have no clue where the distortion came from  
What I can suppose… I have copied it from freshly installed VSCode and perhaps bad line endings come from it

---

<div class="post-metadata">

**Author:** ![sundmoon](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sundmoon](https://forums.powershell.org/u/sundmoon)\
**Post date:** [July 8, 2018, 8:54am UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/7 "2018-07-08T08:54:51Z")

</div>

There is definitely a problem with freshly installed VSCode  
(I am trying to automate my dev client setup with DSC config, doing ‘learning by doing’).

[ 

(Imgur link has been eaten by this forum)

 

Please see extra whitespace injected by Code into the middle of **"Q:"** string - that leads to termination  
What is wrong for me?

](https://imgur.com/27hY2WH)

---

<div class="post-metadata">

**Author:** ![sundmoon](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sundmoon](https://forums.powershell.org/u/sundmoon)\
**Post date:** [July 11, 2018, 1:11am UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/8 "2018-07-11T01:11:45Z")

</div>

Please help to find out the root problem.

Confirmed exception in the powershell console host.  
Can it be bad encoding in git repo (cloned with freshly installed git clone)?

PS C:\dev\> ipmo .\WindowsImageTools\WindowsImageTools\WindowsImageTools.psm1  
WARNING: The names of some imported commands from the module ‘WindowsImageTools’ include unapproved verbs that might  
make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the  
Verbose parameter. For a list of approved verbs, type Get-Verb.

PS C:\dev\> Convert-Wim2VHD -Path ‘H:\HyperVLab\Images\W2016\_GUI.vhdx’ -Index 4 -Size 59GB -DiskLayout UEFI -Dynamic -Sou  
rcePath ‘H:\HypervLab\Media\en\_windows\_server\_2016\_vl\_x64\_dvd\_11636701.iso’ -WhatIf  
What if: [Convert-Wim2VHD] : Overwrite partitions inside [H:\HyperVLab\Images\W2016\_GUI.vhdx] with content of [H:\Hyperv  
Lab\Media\en\_windows\_server\_2016\_vl\_x64\_dvd\_11636701.iso]

PS C:\dev\> $ConvertWim2VHD\_Param = @{  
\>\> Path = ‘H:\HyperVLab\Images\W2016\_GUI.vhdx’  
\>\> Index = 4  
\>\> Size = 59GB  
\>\> DiskLayout = ‘UEFI’  
\>\> Dynamic = $true  
\>\> SourcePath = ‘H:\HyperVLab\Media\en\_windows\_server\_2016\_vl\_x64\_dvd\_11636701\Media\en\_windows\_server\_2016\_vl\_x  
64\_dvd\_11636701.iso’  
\>\> }  
PS C:\dev\> Convert-Wim2VHD @$ConvertWim2VHD\_Param -verbose  
Convert-Wim2VHD : Cannot validate argument on parameter ‘Path’. Cannot bind argument to parameter ‘Path’ because it is  
an empty string.  
At line:1 char:17

- Convert-Wim2VHD @$ConvertWim2VHD\_Param -verbose
- 

```
            ~~~~~~~~~~~~~~~~~~~~~~

```

  - CategoryInfo : InvalidData: (🙂 [Convert-Wim2VHD], ParameterBindingValidationException
  - FullyQualifiedErrorId : ParameterArgumentValidationError,Convert-Wim2VHD

---

<div class="post-metadata">

**Author:** ![robertlandau](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@robertlandau](https://forums.powershell.org/u/robertlandau)\
**Post date:** [July 11, 2018, 12:18pm UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/9 "2018-07-11T12:18:51Z")

</div>

You are calling the function incorrectly

```
PS C:\dev> Convert-Wim2VHD @$ConvertWim2VHD_Param -verbose
```

When splatting remove the $ it should be called as this

```
PS C:\dev> Convert-Wim2VHD @ConvertWim2VHD_Param -verbose
```

> **[about Splatting - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.2&viewFallbackFrom=powershell-6)**
>
> Describes how to use splatting to pass parameters to commands in PowerShell.

---

<div class="post-metadata">

**Author:** ![sundmoon](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sundmoon](https://forums.powershell.org/u/sundmoon)\
**Post date:** [July 12, 2018, 5:15am UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/10 "2018-07-12T05:15:25Z")

</div>

Thank you, bob.  
Shame on me for such an oversight!

I am suffering of the race condition between chicken and egg, trying different modules and still not having a decent stable codebase.  
What a pity with [GitHub - pluralsight/PS-AutoLab-Env: A PowerShell module for creating lab configurations using Lability and Desired State Configuration. This is a complete update of the 3.x versions. Look at README.md for more information.](https://github.com/theJasonHelmick/PS-AutoLab-Env) having had become deprecated

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:35pm UTC](https://forums.powershell.org/t/validatescript-parameter-attribute-messes-with-splatted-input/10936/11 "2024-05-16T20:35:50Z")

</div>

Closed on May 16, 2024, 8:35pm UTC


