当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell:检查 VMware vShield 驱动程序是否已安装并正在运行

作者:精品下载站 日期:2024-12-14 07:15:54 浏览:15 分类:玩电脑

PowerShell:检查 VMware vShield 驱动程序是否已安装并正在运行


VMware vShield 驱动程序是一个名为 vsepflt 的系统驱动程序。

通过运行 msinfo32.exe 并导航到“软件环境系统驱动程序”,可以轻松检查该驱动程序的状态

[玩转系统] PowerShell:检查 VMware vShield 驱动程序是否已安装并正在运行

然而,在具有多个虚拟机的环境中,这可能有点麻烦。这就是为什么我建议使用 PowerShell。

msinfo32 显示的系统驱动程序类别正是 WMI 类 Win32_SystemDriver,因此我编写了一个简短的函数,可用于清点 VMware vShield 驱动程序的状态。它采用一个参数 -ComputerName 并返回一个 PSCustomObject,其中包含已清点的服务器名称和驱动程序的基本属性。

这是一个例子:

[玩转系统] PowerShell:检查 VMware vShield 驱动程序是否已安装并正在运行

我们可以很容易地看到Server01没有安装VShield驱动程序,Server02处于离线状态(或者至少没有响应),而Server03和Server04运行良好。

该函数将以下查询包装在 PowerShell 高级函数中:

Get-WmiObject -Class Win32_SystemDriver -Filter “name=‘vsepflt’ ” -ComputerName $Computer -ErrorAction Stop

function Get-SWVShieldStatus
{
    [Cmdletbinding()]
    Param(
        [Parameter(Mandatory,ValueFromPipeline)]
        [String[]]
        $ComputerName
    )
    Process
    {
        Foreach($Computer in $ComputerName)
        {
            Try
            {
                $VShieldDriver = Get-WmiObject -Class Win32_SystemDriver -Filter "name='vsepflt'" -ComputerName $Computer -ErrorAction Stop
                Write-Verbose -Message "Successfully connected to $Computer"
                [PSCustomObject]@{
                    ComputerName = $Computer
                    DisplayName = $VShieldDriver.DisplayName
                    Name = $VShieldDriver.Name
                    State = $VShieldDriver.State
                    Status = $VShieldDriver.Status
                    Started = $VShieldDriver.Started
                }
            }
            Catch
            {
                Write-Verbose -Message "Failed to inventory $Computer"
                Write-Error -Exception $_.Exception -Message "Failed to inventory $Computer" -Category ConnectionError
                Continue
            }
        }
    }
}

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯