在Power-shell中使用If条件为空显示消息 [英] Display message using If condition is null in Power-shell

查看:133
本文介绍了在Power-shell中使用If条件为空显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

         我正在使用power-shell获取特定产品的列表。如果我没有收到任何信息列表,我想显示信息,因为"此产品不存在任何信息"。

         I am getting list of particular product using power-shell.I want to display the info if i didn't get any list of info as "No information  exist with this product".

       我收到了power-shell中的代码片段,以便找到我想知道天气的办公产品"$ Mylist"。是没有.if null 我想显示消息。任何人都可以帮我解决这个问题

       I had received snippet of code in power-shell to find office product I want to know weather "$Mylist" is null of not .if null  I would like to show message.Can any one help me how can I do this

$ Mylist =  gwmi Win32_Product |?{$ _。名称-match'office'} |选择名称

$Mylist= gwmi Win32_Product |?{$_.Name -match 'office'}|select name

谢谢,质量沟通提供高质量的工作。 http://siddiq-sharepoint2010.blogspot.in/ Siddiqali Mohammad。

Thanks, Quality Communication Provides Quality Work. http://siddiq-sharepoint2010.blogspot.in/ Siddiqali Mohammad .

推荐答案

尝试一下:


Mylist = Get-WmiObject Win32_Product -Filter"名称如'%office% ""

如果(
Mylist = Get-WmiObject Win32_Product -Filter "Name like '%office%'" If (


Mylist){找到了写主机'产品'}
否则{Write-Host'该产品不存在任何信息' }
Mylist) { Write-Host 'Products were found' } Else { Write-Host 'No information exist with this product' }


这篇关于在Power-shell中使用If条件为空显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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