【问题标题】:Check GPU PowerShell检查 GPU PowerShell
【发布时间】:2022-01-27 17:23:18
【问题描述】:

我的 PowerShell 脚本优化显卡 因此,当我调用 GPU Tweaker 时,它会出现此错误 术语“GpuTweaker”未被识别为 cmdlet 函数脚本文件或可运行程序的名称 有人可以编辑我的代码吗?

$GPU = (Get-WmiObject Win32_VideoController).Name
Function GPUTweaker{
    If ($GPU -like "*NVIDIA*") {
        <FunctionName>
    }

    If ($GPU -like "*AMD*") {
        <FunctionName>
    }

    If ($GPU -like "*Intel*") {
        <FunctionName>
    }
}

【问题讨论】:

  • 这个错误意味着函数 GpuTweaker 没有在当前的 powershell 上下文中定义。 @Sycho,你在哪里调用函数 GPUTweaker?
  • @BETOMBO 我修好了谢谢

标签: powershell powershell-2.0


【解决方案1】:

对于-like 运算符,您应该使用通配符,否则它不会返回所需的结果。

在我的例子中:

C:\> $gpu = (Get-WmiObject Win32_VideoController).Name
C:\> $gpu 
Intel(R) UHD Graphics 620

C:\> $gpu -like "Intel"
False

C:\> $gpu -like "*Intel*"
True

C:\> $gpu -like "Intel*" 
True

更多示例请参见about_Comparison_Operators

【讨论】:

    猜你喜欢
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2014-09-24
    • 2012-05-05
    • 1970-01-01
    相关资源
    最近更新 更多