Hi,
I wrote a script that perfectly works without splatting, but it always breaks with splatting.
I don’t know what am I doing wrong, since I do it exactly as in a TechNet example.
Generation = “2” gets screwed up by the forum, not me ![]()
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string[]]
$VMName,
[Parameter(Mandatory = $true)]
[string]
$SwitchName,
[Parameter(Mandatory = $true)]
[string]
$ISOPath
)
process
{
foreach ($name in $VMName)
{
$params = @{
Name = "$name"
MemoryStartupBytes = "1GB"
Generation = "2"
Path = "C:\Lab\VM"
SwitchName = "$SwitchName"
}
New-VM @params
#the script completes perfectly with the line below, but breaks with splatting, becuse the VMs don't get created
#New-VM -Name $name -MemoryStartupBytes 1GB -Generation 2 -Path C:\Lab\VM -SwitchName $SwitchName
New-VHD -Path C:\Lab\VHD\$name\$name.vhdx -SizeBytes 40GB -Dynamic
Set-VMMemory -VMName $name -DynamicMemoryEnabled $true -MinimumBytes 512MB
Add-VMHardDiskDrive -VMName $name -Path C:\Lab\VHD\$name\$name.vhdx
Add-VMDvdDrive -VMName $name -Path $ISOPath
$network = Get-VMNetworkAdapter -VMName $name
$vhd = Get-VMHardDiskDrive -VMName $name
$dvd = Get-VMDvdDrive -VMName $name
Set-VMFirmware -VMName $name -BootOrder $dvd,$network,$vhd
}
}