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.