Hello,
I'm trying to make one command out of multiple if/else statements.
For example I'm looking up a cloud in VMM, when it does exists add "-cloud $cloud" to $command, when it does not exists lookup the default cloud and add -cloud $cloud" to the command.
Maybe a cloud is a bad example but it could also be an IP address (if $IP -ne $null) then add "-ip $IP" to $command.
# Get cloud, if exists
$cloud = get-sccloud -name "Cloudname"
[string]$command = "New-SCVirtualMachine -Name $VMname -VMConfiguration $virtualMachineConfiguration -ReturnImmediately -DelayStartSeconds '0' -RunAsynchronously"
if ($cloud -ne $null){
$command += " -cloud $cloud"
}
else {
$cloud = get-sccloud -name "Default cloud"
$command += " -cloud $cloud"
}When I try the above I will recieve this error:
New-SCVirtualMachine : Cannot bind parameter 'VMConfiguration'. Cannot convert the "Test VM" value of type"System.String" to type "Microsoft.SystemCenter.VirtualMachineManager.BaseVMConfiguration".
And I think the I get this error because the variables are emtpy when converting it to string.
What other type could I use? or other method?
Thanks for any help! :-)