在记事本中代码内容,随便起一个文件名:xx.ps1,用管理员权限打开PowerShell,运行这个ps1脚本。原理是关机前“卸载”V100,重启后能就够正常识别(原因不明)。
——————
#1. 运行方法:在PowerShell窗口中分别运行下列代码
cd x:\ooo
.\xx.ps1
——————
——————
#2. 以下为xx.ps1的代码内容:
# 检查是否以管理员身份运行
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "请以管理员身份运行此脚本!" -ForegroundColor Red
exit
}
# 定义脚本路径和内容
$scriptDir = "C:\Scripts"
$batFilePath = "$scriptDir\Uninstall-GPU.bat"
$psFilePath = "$scriptDir\Uninstall-NVIDIA.ps1"
# 创建脚本目录(如果不存在)
if (-not (Test-Path $scriptDir)) {
New-Item -ItemType Directory -Path $scriptDir | Out-Null
}
# 创建 Uninstall-GPU.bat
@"
@echo off
powershell.exe -ExecutionPolicy Bypass -File "$psFilePath"
"@ | Set-Content -Path $batFilePath
# 创建 Uninstall-NVIDIA.ps1
@"
# 设备名称
`$deviceName = "NVIDIA Tesla V100-SXM2-16GB"
# 获取设备实例ID
`$device = Get-PnpDevice | Where-Object { `$_.FriendlyName -eq `$deviceName }
# 如果找到设备,则卸载
if (`$device) {
pnputil.exe /remove-device `$device.InstanceId
}
"@ | Set-Content -Path $psFilePath
# 配置组策略(设置关机脚本)
$gpoShutdownScriptPath = "C:\Windows\System32\GroupPolicy\Machine\Scripts\Shutdown"
$gpoScriptsIniPath = "$gpoShutdownScriptPath\scripts.ini"
# 创建组策略目录(如果不存在)
if (-not (Test-Path $gpoShutdownScriptPath)) {
New-Item -ItemType Directory -Path $gpoShutdownScriptPath | Out-Null
}
# 更新 scripts.ini 文件
@"
[Shutdown]
0CmdLine=$batFilePath
0Parameters=
"@ | Set-Content -Path $gpoScriptsIniPath -Force
# 刷新组策略
Write-Host "正在更新组策略..." -ForegroundColor Yellow
Invoke-Expression "gpupdate /force"
# 输出成功信息
Write-Host "脚本和组策略配置已完成!" -ForegroundColor Green
Write-Host "Uninstall-GPU.bat 路径: $batFilePath"
Write-Host "Uninstall-NVIDIA.ps1 路径: $psFilePath"
——————