检查项目是否存在,如果不存在则无错误 [英] Check if an item exists without an error if it doesn't exist

查看:39
本文介绍了检查项目是否存在,如果不存在则无错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 PowerShell 检查 IIS Web 应用程序是否存在(或可能存在其他类型的项目).我可以使用 Get-Item 来做到这一点,但是如果该项目不存在,则会报告错误,这会误导运行脚本的用户 - 当实际上一切正常时,它看起来好像出了问题.

I'd like to use PowerShell to check whether an IIS Web Application exists (or potentially some other kind of item). I can do this with Get-Item, but that reports an error if the item doesn't exist, which is misleading to the user running the script - it looks like something went wrong when actually everything is fine.

如何做到这一点而不会出错?

How do I do this without an error?

推荐答案

使用命令... get-item blah -ErrorAction SilentlyContinue

这篇关于检查项目是否存在,如果不存在则无错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆