So first of all i still dont get the exact difference between normal Powershell and PowerCLI with ESXCLI. I really tried unterstanding it how it works etc. So yeah i did some research. Now to my problem
MAIN TASK IM TRYING TO DO: The vCenter excecutes a .ps1 script via POWERCLI it already can restart the vm's as it should. The Task for me is to make a pop-up windows notification for all vm's.
The notification itself looks like this:
Add-Type -AssemblyName System.Windows.Forms
$global:balmsg = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
$balmsg.BalloonTipText = "Die VM startet in 30 Sekunden neu"
$balmsg.BalloonTipTitle = "Achtung!"
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(1)
I installed ESXCLI via a guide i found online i only had to restart the .ini for it to be installed. I then tried some stuff in my code but everything i do gets me an syntax-based error...
$esxcli = Get-EsxCli -VMHost vCenter -V2
esxcli storage nfs list
Invoke-Command -ComputerName $vm -Credential xxx.local\$vm -ScriptBlock { Get-Culture }
$esxcli.shell.cmd("Invoke-Command -ComputerName VM-xxx -ScriptBlock { Get-Culture }", $null, $null, $null, $null)
$esxcli.shell.cmd("Invoke-Command -ComputerName $vm -Credential xxx.local\$vm -ScriptBlock { Get-Culture }")
Invoke-Command -ComputerName VM-xxx -ScriptBlock {
Add-Type -AssemblyName System.Windows.Forms
$global:balmsg = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
$balmsg.BalloonTipText = "Die VM startet in 30 Sekunden neu"
$balmsg.BalloonTipTitle = "Achtung!"
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(1)
}
Thats everything thrown together to see if anything i try works. But sadly it didnt. The errors i get are all syntax-based as far as i could unterstand them so thats why i think that i didnt quite understand how ESXCLI is working.
It would be nice if you guys could help me even just a link to a good tutorial on that specific task im tyring to to would be awesome.
Clearing some things up:
PowerShell (by using PowerCLI) can call ESXCLI, but ESXCLI cannot make PowerShell calls.
You don't happen to mention what version of vSphere you're using, but generally the preference is to be using their vCenter Server Appliance... Which would not give you the ability to install or use PowerShell in a supported manner.
Taking a step back, if I were in your shoes, I would take the ps1 script that's being called and modify it to include your notification code.
It would probably look something like:
Using the above, there's no real reason to reference ESXCLI since you don't need to manage the hosts directly, only the VMs.
Alternatively, there's also a PowerCLI cmdlet known as
Invoke-VMScriptwhich will allow you to run scripts, such as your warning notification, on the VM through VMware Tools instead of usingInvoke-Command. There's no direct network connectivity to the VM required. Docs on Invoke-VMScript