手机
当前位置:查字典教程网 >脚本专栏 >PowerShell >Powershell小技巧之用变量累积记录错误
Powershell小技巧之用变量累积记录错误
摘要:当你使用GC查询文件时,当你没有足够的权限你可能会错过不少错误。你可以使用“–ErrorActionSilentlyContinue”忽略这...

当你使用GC查询文件时,当你没有足够的权限你可能会错过不少错误。你可以使用“–ErrorAction SilentlyContinue”忽略这些错误。

有一个不错的方法来获取这些错误。

我们在Windows目录中查询所有PS脚本文件,将它的文件保存在$PSScripts,同时将错误日志记录在变量ErrorList中:

复制代码 代码如下:

$PSScripts = Get-ChildItem -Path c:windows -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue -ErrorVariable ErrorList

$ErrorList | ForEach-Object {

Write-Warning ('Access denied: ' + $_.CategoryInfo.TargetName)

}

支持所有版本

【Powershell小技巧之用变量累积记录错误】相关文章:

Windows Powershell 定义变量

Powershell小技巧之通过EventLog查看近期电脑开机和关机时间

Powershell小技巧之查看安装的.Net framework版本信息

Powershell小技巧之使用Update-TypeData扩展类型系统

PowerShell中定义多个变量并赋值的例子

Powershell小技巧之使用Copy-Item添加程序到开机启动

PowerShell小技巧之同时使用可选强制参数

Powershell小技巧之保存服务信息

Powershell小技巧之编辑Hosts文件

PowerShell小技巧之调用CloudFlare的SDK查询网站统计信息

精品推荐
分类导航