本文整理匯總了Golang中github.com/mitchellh/packer/powershell.PowerShellCmd.Run方法的典型用法代碼示例。如果您正苦於以下問題:Golang PowerShellCmd.Run方法的具體用法?Golang PowerShellCmd.Run怎麽用?Golang PowerShellCmd.Run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mitchellh/packer/powershell.PowerShellCmd
的用法示例。
在下文中一共展示了PowerShellCmd.Run方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: 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
}
示例8: 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
}
示例9: 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
}
示例10: 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
}
示例11: 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
}
示例12: CompactDisks
func CompactDisks(expPath string, vhdDir string) error {
var script = `
param([string]$srcPath, [string]$vhdDirName)
Get-ChildItem "$srcPath/$vhdDirName" -Filter *.vhd* | %{
Optimize-VHD -Path $_.FullName -Mode Full
}
`
var ps powershell.PowerShellCmd
err := ps.Run(script, expPath, vhdDir)
return err
}
示例13: CopyExportedVirtualMachine
func CopyExportedVirtualMachine(expPath string, outputPath string, vhdDir string, vmDir string) error {
var script = `
param([string]$srcPath, [string]$dstPath, [string]$vhdDirName, [string]$vmDir)
Move-Item -Path $srcPath/*.* -Destination $dstPath
Move-Item -Path $srcPath/$vhdDirName -Destination $dstPath
Move-Item -Path $srcPath/$vmDir -Destination $dstPath
`
var ps powershell.PowerShellCmd
err := ps.Run(script, expPath, outputPath, vhdDir, vmDir)
return err
}
示例14: ShutDown
func ShutDown(vmName string) error {
var script = `
param([string]$vmName)
$vm = Get-VM -Name $vmName -ErrorAction SilentlyContinue
if ($vm.State -eq [Microsoft.HyperV.PowerShell.VMState]::Running) {
Stop-VM -Name $vmName -Confirm:$false
}
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName)
return err
}
示例15: StopVirtualMachine
func StopVirtualMachine(vmName string) error {
var script = `
param([string]$vmName)
$vm = Get-VM -Name $vmName
if ($vm.State -eq [Microsoft.HyperV.PowerShell.VMState]::Running) {
Stop-VM -VM $vm -Confirm:$false
}
`
var ps powershell.PowerShellCmd
err := ps.Run(script, vmName)
return err
}