本文整理匯總了Golang中github.com/mitchellh/packer/powershell.PowerShellCmd類的典型用法代碼示例。如果您正苦於以下問題:Golang PowerShellCmd類的具體用法?Golang PowerShellCmd怎麽用?Golang PowerShellCmd使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了PowerShellCmd類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: verifyPSVersion
func (d *HypervPS4Driver) verifyPSVersion() error {
log.Printf("Enter method: %s", "verifyPSVersion")
// check PS is available and is of proper version
versionCmd := "$host.version.Major"
var ps powershell.PowerShellCmd
cmdOut, err := ps.Output(versionCmd)
if err != nil {
return err
}
versionOutput := strings.TrimSpace(string(cmdOut))
log.Printf("%s output: %s", versionCmd, versionOutput)
ver, err := strconv.ParseInt(versionOutput, 10, 32)
if err != nil {
return err
}
if ver < 4 {
err := fmt.Errorf("%s", "Windows PowerShell version 4.0 or higher is expected")
return err
}
return nil
}
示例2: Run
func (s *StepUnmountSecondaryDvdImages) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
ui.Say("Unmounting Integration Services Setup Disk...")
vmName := state.Get("vmName").(string)
// todo: should this message say removing the dvd?
dvdProperties := state.Get("secondary.dvd.properties").([]DvdControllerProperties)
log.Println(fmt.Sprintf("Found DVD properties %s", len(dvdProperties)))
for _, dvdProperty := range dvdProperties {
controllerNumber := dvdProperty.ControllerNumber
controllerLocation := dvdProperty.ControllerLocation
var script powershell.ScriptBuilder
powershell := new(powershell.PowerShellCmd)
script.WriteLine("param([string]$vmName,[int]$controllerNumber,[int]$controllerLocation)")
script.WriteLine("$vmDvdDrive = Get-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLocation $controllerLocation")
script.WriteLine("if (!$vmDvdDrive) {throw 'unable to find dvd drive'}")
script.WriteLine("Remove-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -ControllerLocation $controllerLocation")
err := powershell.Run(script.String(), vmName, controllerNumber, controllerLocation)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
示例3: Run
func (s *StepWaitForPowerOff) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
ui.Say("Waiting for vm to be powered down...")
var script powershell.ScriptBuilder
script.WriteLine("param([string]$vmName)")
script.WriteLine("(Get-VM -Name $vmName).State -eq [Microsoft.HyperV.PowerShell.VMState]::Off")
isOffScript := script.String()
for {
powershell := new(powershell.PowerShellCmd)
cmdOut, err := powershell.Output(isOffScript, vmName)
if err != nil {
err := fmt.Errorf("Error checking VM's state: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
if cmdOut == "True" {
break
} else {
time.Sleep(time.Second * SleepSeconds)
}
}
return multistep.ActionContinue
}
示例4: CreateExternalVirtualSwitch
func CreateExternalVirtualSwitch(vmName string, switchName string) error {
var script = `
param([string]$vmName,[string]$switchName)
$switch = $null
$names = @('ethernet','wi-fi','lan')
$adapters = foreach ($name in $names) {
Get-NetAdapter -Physical -Name $name -ErrorAction SilentlyContinue | where status -eq 'up'
}
foreach ($adapter in $adapters) {
$switch = Get-VMSwitch -SwitchType External | where { $_.NetAdapterInterfaceDescription -eq $adapter.InterfaceDescription }
if ($switch -eq $null) {
$switch = New-VMSwitch -Name $switchName -NetAdapterName $adapter.Name -AllowManagementOS $true -Notes 'Parent OS, VMs, WiFi'
}
if ($switch -ne $null) {
break
}
}
if($switch -ne $null) {
Get-VMNetworkAdapter -VMName $vmName | Connect-VMNetworkAdapter -VMSwitch $switch
} else {
Write-Error 'No internet adapters found'
}
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, switchName)
return err
}
示例5: SetVirtualMachineVlanId
func SetVirtualMachineVlanId(vmName string, vlanId string) error {
var script = `
param([string]$vmName,[string]$vlanId)
Set-VMNetworkAdapterVlan -VMName $vmName -Access -VlanId $vlanId
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, vlanId)
return err
}
示例6: Cleanup
func (s *StepUpdateIntegrationServices) Cleanup(state multistep.StateBag) {
vmName := state.Get("vmName").(string)
var script powershell.ScriptBuilder
script.WriteLine("param([string]$vmName)")
script.WriteLine("Set-VMDvdDrive -VMName $vmName -Path $null")
powershell := new(powershell.PowerShellCmd)
_ = powershell.Run(script.String(), vmName)
}
示例7: MountFloppyDrive
func MountFloppyDrive(vmName string, path string) error {
var script = `
param([string]$vmName, [string]$path)
Set-VMFloppyDiskDrive -VMName $vmName -Path $path
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, path)
return err
}
示例8: UnmountDvdDrive
func UnmountDvdDrive(vmName string) error {
var script = `
param([string]$vmName)
Get-VMDvdDrive -VMName $vmName | Set-VMDvdDrive -Path $null
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName)
return err
}
示例9: EnableVirtualMachineIntegrationService
func EnableVirtualMachineIntegrationService(vmName string, integrationServiceName string) error {
var script = `
param([string]$vmName,[string]$integrationServiceName)
Enable-VMIntegrationService -VMName $vmName -Name $integrationServiceName
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, integrationServiceName)
return err
}
示例10: ConnectVirtualMachineNetworkAdapterToSwitch
func ConnectVirtualMachineNetworkAdapterToSwitch(vmName string, switchName string) error {
var script = `
param([string]$vmName,[string]$switchName)
Get-VMNetworkAdapter -VMName $vmName | Connect-VMNetworkAdapter -SwitchName $switchName
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, switchName)
return err
}
示例11: SetVirtualMachineCpu
func SetVirtualMachineCpu(vmName string, cpu string) error {
var script = `
param([string]$vmName, [int]$cpu)
Set-VMProcessor -VMName $vmName -Count $cpu
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, cpu)
return err
}
示例12: SetNetworkAdapterVlanId
func SetNetworkAdapterVlanId(switchName string, vlanId string) error {
var script = `
param([string]$networkAdapterName,[string]$vlanId)
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $networkAdapterName -Access -VlanId $vlanId
`
var ps powershell.PowerShellCmd
err := ps.Run(script, switchName, vlanId)
return err
}
示例13: ExportVirtualMachine
func ExportVirtualMachine(vmName string, path string) error {
var script = `
param([string]$vmName, [string]$path)
Export-VM -Name $vmName -Path $path
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, path)
return err
}
示例14: RestartVirtualMachine
func RestartVirtualMachine(vmName string) error {
var script = `
param([string]$vmName)
Restart-VM $vmName -Force -Confirm:$false
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName)
return err
}
示例15: UntagVirtualMachineNetworkAdapterVlan
func UntagVirtualMachineNetworkAdapterVlan(vmName string, switchName string) error {
var script = `
param([string]$vmName,[string]$switchName)
Set-VMNetworkAdapterVlan -VMName $vmName -Untagged
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName $switchName -Untagged
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName, switchName)
return err
}