简体   繁体   中英

Powershell Workflow not able to use -parameters to create a VM

I am having a problem with my Powershell Workflow that I am authoring in Windows Azure Pack Admin Site. In Powershell ISE, the following works but in Service Management Portal Admin Site Runbook Authoring, it does not work. Where it is getting stuck is that it is saying that it cannot validate the arguments passed -Name. I remove -Name out and now -FullName doesnt work. It seems like all the switch parameters for the command is not working. Can anyone help me out?

param (

[string]$DomainAdminAcct,
[string]$DomainAdminPass,
[string]$ServerName

)

InlineScript {
Add-PSSnapin VMWare.VimAutomation.Core
$vCenter = "test300"
Connect-ViServer -server $vCenter -ErrorAction Stop


$myCluster = Get-Cluster -Name "DC Test"
$myTemplate = Get-Template -Name "2012dc" -Location "our company"
$OSCustomizationSpec = New-OSCustomizationSpec –Name “$ServerName” –FullName “$ServerName” –OrgName “our company” –Domain “our.domain.com” –DomainUsername “$DomainAdminAcct” –DomainPassword "$DomainAdminPass" -AdminPassword "changeme" -ChangeSid
New-VM -Name $ServerName  -ResourcePool $myCluster -Template $myTemplate -OSCustomizationSpec $OSCustomizationSpec  

 }
}

Sounds like you have Hyper-V and PowerCLI modules loaded and the commands are conflicting. It is trying to run New-VM from the Hyper-V module. You can confirm this by running:

get-command New-VM -all

You should see two commands one from the Hyper-V module and one from the Vmware module. To get past the problem you can add the module name to the command name:

VMware.VimAutomation.Core\New-VM

要在INLINESTRING结构中使用参数,必须使用$ using:<>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM