提取ClusterName RegularExpressions [英] Extracting ClusterName RegularExpressions

查看:51
本文介绍了提取ClusterName RegularExpressions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正则表达式,它将给出计算机名称,群集名称& OSinfo

I have a regular expression which will give the computername, cluster name & OSinfo

Get-QADComputer | ? {$ .osname -match 2008-和$ .computername -match hv} |
选择@ {Name = ComputerName; Expression = {$ _。computername.replace( $,)}}

, @ {Name = ClusterName; Expression = {$ .computername.replace( $,); $ .computername.replace( n [0-9] [0-9] ,)}},@ {Name = OperatingSystem; Expression = {$ _。osname}}

Get-QADComputer | ? {$.osname -match "2008" -and $.computername -match "hv"} | Select @{Name="ComputerName";Expression={$_.computername.replace("$","")}} ,@{Name="ClusterName";Expression={$.computername.replace("$","");$.computername.replace("n[0-9][0-9]","")}},@{Name="OperatingSystem";Expression={$_.osname}}

现在我面临的问题是提取集群名称,例如,如果计算机名称输出为ADFCGS1N01 $,则
,我希望群集名称看起来像ADFCGSN1,我想删除N之后的所有字符以获得群集名称,

Now the problem im facing is in extracting the clustername, for example if output of computer name is ADFCGS1N01$, i wanted the cluster name to look like ADFCGSN1, i wanted to remove all the characters after N to get cluster name,

有人可以帮我吗

推荐答案

这是否给您正确的价值?

Does this gives you the correct value?

Get-QADComputer -OSName *2008* -Name *hv* | Select -ExpandProperty Name

根据您的评论,删除名称末尾的N + 2位数字,包括美元(如果存在):

Per your comment, remove the N+2 digits from the end of name, including the dollar (if exists):

Get-QADComputer -OSName *2008* -Name *hv* | Foreach-Object {$_.Name -replace 'N\d{2}\$?$'}

这篇关于提取ClusterName RegularExpressions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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