获取系统环境变量 dir env:
使用语法:$env:USERPROFILE
function check{
$device = Get-WmiObject Win32_PNPEntity
$erro = $device |select Name,Status | Export-Csv "$env:USERPROFILE\Desktop\device.csv"
$name = Get-Content "$env:USERPROFILE\Desktop\device.csv" | where{$_ -match "Error"}
if($name -match "Error"){
"Device Manager Check fail" >> $env:USERPROFILE\Desktop\log.txt}}
check{}