Public/Open-PBVMConsoleWindow.ps1
function Open-PBVMConsoleWindow { <# .SYNOPSIS PoshBot command to open console window to specified VM. .EXAMPLE !openvmconsole vm1 #> [PoshBot.BotCommand(CommandName = 'openvmconsole')] [cmdletbinding()] param( [PoshBot.FromConfig()] [parameter(Mandatory)] [hashtable]$Connection, [parameter(Position = 0, Mandatory = $true, ValueFromRemainingArguments = $true)] [string[]]$vm ) #Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false $creds = [pscredential]::new($Connection.Username, ($Connection.Password | ConvertTo-SecureString -AsPlainText -Force)) $null = Connect-VIServer -Server $Connection.Server -Credential $creds if ($vm) { $objects = Get-VM $vm | Open-VMConsoleWindow -UrlOnly } else { Exit } $ResponseSplat = @{ Text = Format-PBvSphereObject -Object $objects -FunctionName $MyInvocation.MyCommand.Name AsCode = $true } Disconnect-Viserver -Confirm:$false New-PoshBotTextResponse @ResponseSplat } |