Update powershell messaging functions to not include second `-` character.

This commit is contained in:
Chris Roberts 2018-06-12 15:32:29 -07:00
parent e43a94b797
commit 57842d7269
25 changed files with 42 additions and 42 deletions

View File

@ -5,4 +5,4 @@ $result = @{
result = $check
}
Write-Output-Message $(ConvertTo-Json $result)
Write-OutputMessage $(ConvertTo-Json $result)

View File

@ -13,6 +13,6 @@ $ErrorActionPreference = "Stop"
try {
Hyper-V\New-VHD -Path $Destination -ParentPath $Source
} catch {
Write-Error-Message "Failed to clone drive: ${PSItem}"
Write-ErrorMessage "Failed to clone drive: ${PSItem}"
exit 1
}

View File

@ -26,7 +26,7 @@ $ErrorActionPreference = "Stop"
try {
$VM = Hyper-V\Get-VM -Id $VMID
} catch {
Write-Error-Message "Failed to locate VM: ${PSItem}"
Write-ErrorMessage "Failed to locate VM: ${PSItem}"
exit 1
}
@ -34,7 +34,7 @@ if($Processors) {
try {
Set-VagrantVMCPUS -VM $VM -CPUCount ($Processors -as [int])
} catch {
Write-Error-Message "Failed to configure CPUs: ${PSItem}"
Write-ErrorMessage "Failed to configure CPUs: ${PSItem}"
exit 1
}
}
@ -43,7 +43,7 @@ if($Memory -or $MaxMemory) {
try {
Set-VagrantVMMemory -VM $VM -Memory $Memory -MaxMemory $MaxMemory
} catch {
Write-Error-Message "Failed to configure memory: ${PSItem}"
Write-ErrorMessage "Failed to configure memory: ${PSItem}"
exit 1
}
}
@ -52,7 +52,7 @@ if($AutoStartAction -or $AutoStopAction) {
try {
Set-VagrantVMAutoActions -VM $VM -AutoStartAction $AutoStartAction -AutoStopAction $AutoStopAction
} catch {
Write-Error-Message "Failed to configure automatic actions: ${PSItem}"
Write-ErrorMessage "Failed to configure automatic actions: ${PSItem}"
exit 1
}
}
@ -66,7 +66,7 @@ if($VirtualizationExtensions) {
try {
Set-VagrantVMVirtExtensions -VM $VM -Enabled $virtex
} catch {
Write-Error-Message "Failed to configure virtualization extensions: ${PSItem}"
Write-ErrorMessage "Failed to configure virtualization extensions: ${PSItem}"
exit 1
}
@ -75,7 +75,7 @@ if($SwitchID) {
$SwitchName = Get-VagrantVMSwitch -NameOrID $SwitchID
Set-VagrantVMSwitch -VM $VM -SwitchName $SwitchName
} catch {
Write-Error-Message "Failed to configure network adapter: ${PSItem}"
Write-ErrorMessage "Failed to configure network adapter: ${PSItem}"
}
}
@ -90,6 +90,6 @@ if($EnableCheckpoints) {
try {
Hyper-V\Set-VM -VM $VM -CheckpointType $checkpoints
} catch {
Write-Error-Message "Failed to ${CheckpointAction} checkpoints on VM: ${PSItem}"
Write-ErrorMessage "Failed to ${CheckpointAction} checkpoints on VM: ${PSItem}"
exit 1
}

View File

@ -12,6 +12,6 @@ try {
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-V\Checkpoint-VM $VM -SnapshotName $SnapName
} catch {
Write-Error-Message "Failed to create snapshot: ${PSItem}"
Write-ErrorMessage "Failed to create snapshot: ${PSItem}"
exit 1
}

View File

@ -12,5 +12,5 @@ try {
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-V\Remove-VMSnapshot $VM -Name $SnapName
} catch {
Write-Error-Message "Failed to delete snapshot: ${PSItem}"
Write-ErrorMessage "Failed to delete snapshot: ${PSItem}"
}

View File

@ -11,6 +11,6 @@ try {
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-V\Remove-VM $VM -Force
} catch {
Write-Error-Message "Failed to delete VM: ${PSItem}"
Write-ErrorMessage "Failed to delete VM: ${PSItem}"
exit 1
}

View File

@ -13,7 +13,7 @@ try {
$vm = Hyper-V\Get-VM -Id $VmId
$vm | Hyper-V\Export-VM -Path $Path
} catch {
Write-Error-Message "Failed to export VM: ${PSItem}"
Write-ErrorMessage "Failed to export VM: ${PSItem}"
exit 1
}
@ -24,6 +24,6 @@ try {
Remove-Item -Path $Path/Snapshots -Force -Recurse
Remove-Item -Path $Path/$name -Force
} catch {
Write-Error-Message "Failed to format exported box: ${PSItem}"
Write-ErrorMessage "Failed to format exported box: ${PSItem}"
exit 1
}

View File

@ -120,4 +120,4 @@ $resultHash = @{
message = "OK"
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result
Write-OutputMessage $result

View File

@ -10,7 +10,7 @@ $ErrorActionPreference = "Stop"
try {
$vm = Hyper-V\Get-VM -Id $VmId
} catch {
Write-Error-Message "Failed to locate VM: ${PSItem}"
Write-ErrorMessage "Failed to locate VM: ${PSItem}"
exit 1
}
@ -57,12 +57,12 @@ try {
ip = $guest_ipaddress
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result
Write-OutputMessage $result
} else {
Write-Error-Message "Failed to determine IP address"
Write-ErrorMessage "Failed to determine IP address"
exit 1
}
} catch {
Write-Error-Message "Unexpected error while detecting network configuration: ${PSItem}"
Write-ErrorMessage "Unexpected error while detecting network configuration: ${PSItem}"
exit 1
}

View File

@ -25,8 +25,8 @@ try {
mac = "$mac_address"
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result
Write-OutputMessage $result
} catch {
Write-Error-Message "Unexpected error while fetching MAC: ${PSItem}"
Write-ErrorMessage "Unexpected error while fetching MAC: ${PSItem}"
exit 1
}

View File

@ -7,4 +7,4 @@
$Switches = @(Hyper-V\Get-VMSwitch `
| Select-Object Name,SwitchType,NetAdapterInterfaceDescription,Id)
Write-Output-Message $(ConvertTo-JSON $Switches)
Write-OutputMessage $(ConvertTo-JSON $Switches)

View File

@ -46,4 +46,4 @@ $resultHash = @{
status = "$Status"
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result
Write-OutputMessage $result

View File

@ -6,4 +6,4 @@ $result = @{
result = $check
}
Write-Output-Message $(ConvertTo-Json $result)
Write-OutputMessage $(ConvertTo-Json $result)

View File

@ -30,8 +30,8 @@ try {
$Result = @{
id = $VM.Id.Guid;
}
Write-Output-Message (ConvertTo-Json $Result)
Write-OutputMessage (ConvertTo-Json $Result)
} catch {
Write-Error-Message "${PSItem}"
Write-ErrorMessage "${PSItem}"
exit 1
}

View File

@ -11,9 +11,9 @@ try {
$VM = Hyper-V\Get-VM -Id $VmId
$Snapshots = @(Hyper-V\Get-VMSnapshot $VM | Select-Object Name)
} catch {
Write-Error-Message "Failed to get snapshot list: ${PSItem}"
Write-ErrorMessage "Failed to get snapshot list: ${PSItem}"
exit 1
}
$result = ConvertTo-json $Snapshots
Write-Output-Message $result
Write-OutputMessage $result

View File

@ -12,6 +12,6 @@ try {
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-V\Restore-VMSnapshot $VM -Name $SnapName -Confirm:$false
} catch {
Write-Error-Message "Failed to restore snapshot: ${PSItem}"
Write-ErrorMessage "Failed to restore snapshot: ${PSItem}"
exit 1
}

View File

@ -11,6 +11,6 @@ try {
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-V\Resume-VM $VM
} catch {
Write-Error-Message "Failed to resume VM: ${PSItem}"
Write-ErrorMessage "Failed to resume VM: ${PSItem}"
exit 1
}

View File

@ -12,13 +12,13 @@ $ErrorActionPreference = "Stop"
try {
$VM = Hyper-V\Get-VM -Id $VMID
} catch {
Write-Error-Message "Failed to locate VM: ${PSItem}"
Write-ErrorMessage "Failed to locate VM: ${PSItem}"
exit 1
}
try {
Hyper-V\Set-VM -VM $VM -NewVMName $VMName
} catch {
Write-Error-Message "Failed to assign new VM name ${VMName}: ${PSItem}"
Write-ErrorMessage "Failed to assign new VM name ${VMName}: ${PSItem}"
exit 1
}

View File

@ -13,6 +13,6 @@ try {
$vm = Hyper-V\Get-VM -Id $VmId
Hyper-V\Set-VMNetworkAdapter $vm -StaticMacAddress $Mac
} catch {
Write-Error-Message "Failed to set VM MAC address: ${PSItem}"
Write-ErrorMessage "Failed to set VM MAC address: ${PSItem}"
exit 1
}

View File

@ -18,5 +18,5 @@ try {
Hyper-V\Set-VMNetworkAdapterVlan $vm -Access -Vlanid $VlanId
}
catch {
Write-Error-Message "Failed to set VM's Vlan ID $_"
Write-ErrorMessage "Failed to set VM's Vlan ID $_"
}

View File

@ -14,7 +14,7 @@ $ErrorActionPreference = "Stop"
try {
$VM = Hyper-V\Get-VM -Id $VMID
} catch {
Write-Error-Message "Failed to locate VM: ${PSItem}"
Write-ErrorMessage "Failed to locate VM: ${PSItem}"
exit 1
}
@ -22,6 +22,6 @@ try {
Set-VagrantVMService -VM $VM -Name $Name -Enable $Enable
} catch {
if($Enable){ $action = "enable" } else { $action = "disable" }
Write-Error-Message "Failed to ${action} VM integration service ${Name}: ${PSItem}"
Write-ErrorMessage "Failed to ${action} VM integration service ${Name}: ${PSItem}"
exit 1
}

View File

@ -19,8 +19,8 @@ try {
name = "$name"
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result
Write-OutputMessage $result
} catch {
Write-Error-Message "Failed to start VM ${PSItem}"
Write-ErrorMessage "Failed to start VM ${PSItem}"
exit 1
}

View File

@ -12,6 +12,6 @@ try{
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-V\Stop-VM $VM -Force
} catch {
Write-Error-Message "Failed to stop VM: ${PSItem}"
Write-ErrorMessage "Failed to stop VM: ${PSItem}"
exit 1
}

View File

@ -11,6 +11,6 @@ try{
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-V\Suspend-VM $VM
} catch {
Write-Error-Message "Failed to suspend VM: ${PSItem}"
Write-ErrorMessage "Failed to suspend VM: ${PSItem}"
exit 1
}

View File

@ -3,7 +3,7 @@
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
function Write-Error-Message {
function Write-ErrorMessage {
param (
[parameter (Mandatory=$true,Position=0)]
[string] $Message
@ -16,7 +16,7 @@ function Write-Error-Message {
Write-Host "===End-Error==="
}
function Write-Output-Message {
function Write-OutputMessage {
param (
[parameter (Mandatory=$true,Position=0)]
[string] $Message