为什么 powercli 脚本在执行期间不接受可变参数?
why powercli script is not accepting the variable parameters during the execution?
当我尝试运行 这个 powercli 脚本低于错误
The argument is null or empty. Provide an argument that is not null or empty, and then try the | command again
但它正在使用静态值。任何线索为什么会这样。这是带参数的命令
/usr/bin/pwsh /ansible-vmware/vmwarehost-config-playbooks/lag-add-host.ps1 -vcenter_fqdn "10.10.0.1" -vcenter_username "xxxxxx.abc.com" -vcenter_password "XXXX" -newhostname "hostdone1" -domainname "abc.com" -dvswitchname_1 "dv1" -nic1_pnicmac1 "ac:1f:6b:cb:83:3a" -cluster_name "xyzclr" -lag_name1 "lag1-0"
脚本内容:
#!/usr/bin/pwsh -command
param(
[String] $vcenter_fqdn,
[String] $vcenter_username,
[String] $vcenter_password,
[String] $newhostname,
[String] $domainname,
[String] $dvswitchname_1,
[String] $cluster_name,
[String] $lag_name1,
[String] $nic1_pnicmac1
)
# VC connectivity
Write-Host "Connecting to VC host " $vcenter_fqdn
Connect-VIServer -Server $vcenter_fqdn -User $vcenter_username -Password $vcenter_password -Force
$esxName1 = Get-cluster -Name $cluster_name | Get-VMhost -Name $newhostname.$domainname
$esxName=$esxName1.name
$vdsName1 = Get-VDSwitch $dvswitchname_1
$vdsName = $vdsName1.name
Add-VDSwitchVMHost -VMHost $esxName -VDSwitch $vdsName1
$esxihostnic1 = Get-VMHost hostdone1.examlab.com | Get-VMHostNetworkAdapter -Physical | Where-Object {$_.Mac -eq "$nic1_pnicmac1"}
$pnicName = $esxihostnic1.name
$uplinkName = $lag_name1
#!/usr/bin/pwsh -command
param(
[String] $vcenter_fqdn,
[String] $vcenter_username,
[String] $vcenter_password,
[String] $newhostname,
[String] $domainname,
[String] $dvswitchname_1,
[String] $cluster_name,
[String] $lag_name1,
[String] $nic1_pnicmac1
)
# VC connectivity
Write-Host "Connecting to VC host " $vcenter_fqdn
Connect-VIServer -Server $vcenter_fqdn -User $vcenter_username -Password $vcenter_password -Force
$esxName1 = Get-cluster -Name $cluster_name | Get-VMhost -Name $newhostname.$domainname
$esxName=$esxName1.name
$vdsName1 = Get-VDSwitch "$dvswitchname_1"
$vdsName = $vdsName1.name
Add-VDSwitchVMHost -VMHost $esxName -VDSwitch $vdsName1
$esxihostnic1 = Get-VMHost hostdone1.examlab.com | Get-VMHostNetworkAdapter -Physical | Where-Object {$_.Mac -eq "$nic1_pnicmac1"}
$pnicName = $esxihostnic1.name
$uplinkName = $lag_name1
当我尝试运行 这个 powercli 脚本低于错误
The argument is null or empty. Provide an argument that is not null or empty, and then try the | command again
但它正在使用静态值。任何线索为什么会这样。这是带参数的命令
/usr/bin/pwsh /ansible-vmware/vmwarehost-config-playbooks/lag-add-host.ps1 -vcenter_fqdn "10.10.0.1" -vcenter_username "xxxxxx.abc.com" -vcenter_password "XXXX" -newhostname "hostdone1" -domainname "abc.com" -dvswitchname_1 "dv1" -nic1_pnicmac1 "ac:1f:6b:cb:83:3a" -cluster_name "xyzclr" -lag_name1 "lag1-0"
脚本内容:
#!/usr/bin/pwsh -command
param(
[String] $vcenter_fqdn,
[String] $vcenter_username,
[String] $vcenter_password,
[String] $newhostname,
[String] $domainname,
[String] $dvswitchname_1,
[String] $cluster_name,
[String] $lag_name1,
[String] $nic1_pnicmac1
)
# VC connectivity
Write-Host "Connecting to VC host " $vcenter_fqdn
Connect-VIServer -Server $vcenter_fqdn -User $vcenter_username -Password $vcenter_password -Force
$esxName1 = Get-cluster -Name $cluster_name | Get-VMhost -Name $newhostname.$domainname
$esxName=$esxName1.name
$vdsName1 = Get-VDSwitch $dvswitchname_1
$vdsName = $vdsName1.name
Add-VDSwitchVMHost -VMHost $esxName -VDSwitch $vdsName1
$esxihostnic1 = Get-VMHost hostdone1.examlab.com | Get-VMHostNetworkAdapter -Physical | Where-Object {$_.Mac -eq "$nic1_pnicmac1"}
$pnicName = $esxihostnic1.name
$uplinkName = $lag_name1
#!/usr/bin/pwsh -command
param(
[String] $vcenter_fqdn,
[String] $vcenter_username,
[String] $vcenter_password,
[String] $newhostname,
[String] $domainname,
[String] $dvswitchname_1,
[String] $cluster_name,
[String] $lag_name1,
[String] $nic1_pnicmac1
)
# VC connectivity
Write-Host "Connecting to VC host " $vcenter_fqdn
Connect-VIServer -Server $vcenter_fqdn -User $vcenter_username -Password $vcenter_password -Force
$esxName1 = Get-cluster -Name $cluster_name | Get-VMhost -Name $newhostname.$domainname
$esxName=$esxName1.name
$vdsName1 = Get-VDSwitch "$dvswitchname_1"
$vdsName = $vdsName1.name
Add-VDSwitchVMHost -VMHost $esxName -VDSwitch $vdsName1
$esxihostnic1 = Get-VMHost hostdone1.examlab.com | Get-VMHostNetworkAdapter -Physical | Where-Object {$_.Mac -eq "$nic1_pnicmac1"}
$pnicName = $esxihostnic1.name
$uplinkName = $lag_name1