0

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

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}}

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,

Can some one please help me with the same

PowerShell
  • 1,991
  • 8
  • 35
  • 57

1 Answers1

1

Does this gives you the correct value?

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

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}\$?$'}
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
  • PS C:\Users\vinith> Get-QADComputer LYGTFBL1N02$ | Select -ExpandProperty Name LYGTFBL1N02 Hi SHay what i wanted is the output to be LYGTFBL1, there should be no characters after "N" – PowerShell Sep 23 '11 at 07:46
  • All computers in the command I posted have 02$ at the end of the name? – Shay Levy Sep 23 '11 at 07:48
  • Hi Shay, what i wanted is that all the computernames which have a N[0-9][0-9] should be replaced by null, for example if server name is LHYTFC1N01, the output should be LHYTFC1 – PowerShell Sep 23 '11 at 07:57
  • PS C:\Users\supervinith> Get-QADComputer -Name LHPHT2N01 | Foreach-Object {$_.Name -replace '\d{2}$'} LHPHT2N Hi shay i wanted also the "N" to go away, i wanted my output to be LHPHT2 – PowerShell Sep 23 '11 at 08:10
  • Check the thread again, the pattern you need to use is 'N\d{2}\$?$' – Shay Levy Sep 23 '11 at 08:14
  • Hi @Shay Levy can you please help me with this question http://stackoverflow.com/questions/8181031/remove-favourite-targets-disconnect-iscsi-targets-using-iscsicli-exe-powersh – PowerShell Nov 18 '11 at 10:35