这是我的剧本:
$ScriptText = $Adapter = Get-NetAdapter |
Select-Object InterfaceDescription,Name | %{
if ($Adapter.InterfaceDescription -match "vmxnet3") {
Get-NetAdapter -Name $Adapter.Name | Rename-NetAdapter -NewName "LAN"
}
}
Invoke-VMScript –VM "DC01” -guestuser “administrator” -guestpassword “password” -ScriptText $ScriptText
产生以下错误:
Invoke-VMScript : 26-8-2015 11:34:40 Invoke-VMScript
Value cannot be found for the mandatory parameter ScriptText
At line:7 char:1
+ Invoke-VMScript –VM "DC01” -guestuser “administrator” -guestpassword “password” ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
字符串$ScriptText
应包含引号之间的命令。
$ScriptText = "Get-NetAdapter | Select InterfaceDescription,Name | % {if($_.InterfaceDescription -match 'vmxnet3') {Get-NetAdapter -Name $_.Name | Rename-NetAdapter -NewName ""LAN""}}"
Invoke-VMScript
通过提供的凭据登录并运行脚本。
Invoke-VMScript –VM "DC01” -guestuser “administrator” -guestpassword “password” -ScriptText $ScriptText
此时我有以下错误:
% : The term '.InterfaceDescription' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:56
+ & {Get-NetAdapter | Select InterfaceDescription,Name | % {if(.InterfaceDescripti ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.InterfaceDescription:String) [ForEach-Object], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.ForEachObjectCommand