Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell powerCLI与ESCXLI一起运行带有windows通知脚本的命令_Powershell_Powercli_Esx - Fatal编程技术网

Powershell powerCLI与ESCXLI一起运行带有windows通知脚本的命令

Powershell powerCLI与ESCXLI一起运行带有windows通知脚本的命令,powershell,powercli,esx,Powershell,Powercli,Esx,因此,首先,我仍然没有得到普通Powershell和使用ESXCLI的PowerCLI之间的确切区别。我真的试着去理解它是如何工作的,所以我做了一些研究。 现在来谈谈我的问题 我要做的主要任务: vCenter通过POWERCLI执行.ps1脚本—它已经可以按其应该的方式重新启动vm。我的任务是为所有虚拟机发出弹出窗口通知。 通知本身如下所示: Add-Type -AssemblyName System.Windows.Forms $global:balmsg = New-Object Syst

因此,首先,我仍然没有得到普通Powershell和使用ESXCLI的PowerCLI之间的确切区别。我真的试着去理解它是如何工作的,所以我做了一些研究。 现在来谈谈我的问题

我要做的主要任务: vCenter通过POWERCLI执行.ps1脚本—它已经可以按其应该的方式重新启动vm。我的任务是为所有虚拟机发出弹出窗口通知。

通知本身如下所示:

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)
我通过在线找到的指南安装了ESXCLI,只需重新启动.ini即可安装。 然后我在我的代码中尝试了一些东西,但我做的每件事都会导致一个基于语法的错误

$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)
}
这是所有的东西放在一起,看看我尝试的东西是否有效。但遗憾的是,事实并非如此。 我得到的错误都是基于语法的,因为我无法理解它们,所以我认为我不太了解ESXCLI是如何工作的


如果你们能帮助我,那就太好了,哪怕只是一个链接到一个很好的教程,关于我要做的特定任务,那就太棒了。

清理一些东西:

  • PowerShell:跨平台脚本语言和相关shell
  • PowerCLI:由VMware创建和维护的一组PowerShell模块,用于与VMware产品(包括vCenter和ESXi主机)交互
  • ESXCLI:一组命令,可通过专用于管理ESXi主机的最常见shell执行,也可在主机上使用。如果有帮助的话,它们很可能是基于perl的
PowerShell(通过使用PowerCLI)可以调用ESXCLI,但ESXCLI无法进行PowerShell调用

您没有提到您正在使用的vSphere的版本,但通常首选使用他们的vCenter Server设备。。。这将无法让您以受支持的方式安装或使用PowerShell

退一步说,如果我站在你的立场上,我会使用正在调用的ps1脚本并修改它以包含你的通知代码

它可能看起来像:

# Connect to vCenter Server
Connect-VIServer    

# Gathers the VMs to be restarted 
$vms = Get-VM

# Create a foreach loop to interact with each VM that was found in the prior step 
foreach ($vm in $vms) {
  
  # Using PowerShell to connect to the VM through the OS, run your invoke-command notification/alert
  Invoke-Command -ComputerName $vm.name -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)
  }

  # Sleep for 30 seconds
  Start-Sleep -Seconds 30

  # Restart virtual machine
  Restart-VMGuest -VM $vm
}

# Disconnect from the vCenter server
Disconnect-VIServer
使用上述方法,没有真正的理由引用ESXCLI,因为您不需要直接管理主机,只需要管理虚拟机


另外,还有一个名为
Invoke-VMScript
的PowerCLI cmdlet,它允许您通过VMware工具在VM上运行脚本,例如警告通知,而不是使用
Invoke命令
。不需要到VM的直接网络连接

感谢您对该主题的帮助和澄清。我已经按照你的建议尝试过了,但是我得到了一个错误,说“身份验证主题不是Kerberos,或者客户端计算机不在域中。”客户端计算机在域中,所以我认为是Kerbers自动身份验证。。。。但我不知道它的确切含义。你知道这件事吗?