<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need tips to format output generated by PSTK cmlet Invoke-NaSsh in Microsoft Virtualization Discussions</title>
    <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114836#M4688</link>
    <description>&lt;P&gt;Many Thanks Andrew; if possible plz explain the regex[$output -match 'Status:\s*(.*)\b'] that you have used as I am new to use regex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Charan&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2016 15:19:00 GMT</pubDate>
    <dc:creator>netappwala</dc:creator>
    <dc:date>2016-01-20T15:19:00Z</dc:date>
    <item>
      <title>Need tips to format output generated by PSTK cmlet Invoke-NaSsh</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114811#M4686</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone please give me tips to format, cut and copy the output generated by PSTK cmdlet Invoke-NaSsh.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The specific requirement what I am looking is to grep few records from the outpt of [Invoke-NaSsh "sp status"]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Charan&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 22:17:12 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114811#M4686</guid>
      <dc:creator>netappwala</dc:creator>
      <dc:date>2025-06-04T22:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need tips to format output generated by PSTK cmlet Invoke-NaSsh</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114816#M4687</link>
      <description>&lt;P&gt;Hello Charan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using regular expressions you can create a custom object which holds the information. &amp;nbsp;Here is a crude example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$output = "Service Processor           Status: Online
    Firmware Version:   1.0
    Mgmt MAC Address:   00:A0:98:13:9C:22
    Ethernet Link:      up
    Using DHCP:         yes
IPv4 configuration:
    IP Address:         172.22.131.145
    Netmask:            255.255.224.0
    Gateway:            172.22.128.1"

$spStatus = "" | Select Status,Firmware,MAC,LinkState,UsingDHCP,IP_Address,Netmask,Gateway

if ($output -match 'Status:\s*(.*)\b') {
    $matches
    $spStatus.Status = $matches[1]
} else {
    $spStatus.Status = "unknown"
}

if ($output -match 'Firmware Version:\s*(\d*\.\d*)') {
    $matches
    $spStatus.Firmware = $matches[1]
} else {
    $spStatus.Firmware = "unknown"
}

if ($output -match 'Mgmt MAC Address:\s*(.*)\b') {
    $matches
    $spStatus.MAC = $matches[1]
} else {
    $spStatus.MAC = "unknown"
}

if ($output -match 'Ethernet Link:\s*(.*)\b') {
    $matches
    $spStatus.LinkState = $matches[1]
} else {
    $spStatus.LinkState = "unknown"
}

if ($output -match 'Using DHCP:\s*(.*)\b') {
    $matches
    $spStatus.UsingDHCP = $matches[1]
} else {
    $spStatus.UsingDHCP = "unknown"
}

if ($output -match 'IP Address:\s*(.*)\b') {
    $matches
    $spStatus.IP_Address = $matches[1]
} else {
    $spStatus.IP_Address = "unknown"
}

if ($output -match 'Netmask:\s*(.*)\b') {
    $matches
    $spStatus.Netmask = $matches[1]
} else {
    $spStatus.Netmask = "unknown"
}

if ($output -match 'Gateway:\s*(.*)\b') {
    $matches
    $spStatus.Gateway = $matches[1]
} else {
    $spStatus.Gateway = "unknown"
}

$spStatus&lt;/PRE&gt;&lt;P&gt;Which would output this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Status     : Online
Firmware   : 1.0
MAC        : 00:A0:98:13:9C:22
LinkState  : up
UsingDHCP  : yes
IP_Address : 172.22.131.145
Netmask    : 255.255.224.0
Gateway    : 172.22.128.1&lt;/PRE&gt;&lt;P&gt;Since it's an object you can address properties during control statements:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if ($spStatus.LinkState -ne "up") {
  # do something
}&lt;/PRE&gt;&lt;P&gt;Hope that helps,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 21:51:13 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114816#M4687</guid>
      <dc:creator>asulliva</dc:creator>
      <dc:date>2016-01-19T21:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need tips to format output generated by PSTK cmlet Invoke-NaSsh</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114836#M4688</link>
      <description>&lt;P&gt;Many Thanks Andrew; if possible plz explain the regex[$output -match 'Status:\s*(.*)\b'] that you have used as I am new to use regex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Charan&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 15:19:00 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114836#M4688</guid>
      <dc:creator>netappwala</dc:creator>
      <dc:date>2016-01-20T15:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need tips to format output generated by PSTK cmlet Invoke-NaSsh</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114840#M4689</link>
      <description>&lt;P&gt;Regular expressions are used for pattern matching against strings. &amp;nbsp;They can be used multiple ways, the most common being to&amp;nbsp;check if a string contains some pattern, or to extract some text which matches a pattern. &amp;nbsp;In this instance we're doing the latter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if ($output -match 'Netmask:\s*(.*)\b') {
    $matches
    $spStatus.Netmask = $matches[1]
} else {
    $spStatus.Netmask = "unknown"
}&lt;/PRE&gt;&lt;P&gt;The first line checks to see if the string $output matches against the regular expression 'Netmask:\s*(.*)\b'. &amp;nbsp;If it matches it goes into the if statement. &amp;nbsp;Breaking out the regex used, there's a couple of things going on...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# look for the text "Netmask:" (no quotes, but colon required)
Netmask:

# followed by any number of white space characters, e.g. tab or space
# the \s is short for whitespace, the * is short for 0 or more
\s*

# capture any text after the last white space character
# the parenthesis denotes "capture text", the period is short for any character,
# and the * is short for any number of occurrences
(.*)

# stop capturing at the end of the word.  \b is short for "word boundary"
\b&lt;/PRE&gt;&lt;P&gt;Assuming it matches the regex, the extracted text will be found in a created array variable, $matches, with the first value ($matches[0]) being equal to the whole of the matched text, and the second and later values ($matches[1], etc.) equal to the extracted values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a huge amount of information on regex out there. &amp;nbsp;There's a decent reference of the special quantifiers and identifiers &lt;A href="http://powershell.com/cs/blogs/ebookv2/archive/2012/03/20/chapter-13-text-and-regular-expressions.aspx" target="_self"&gt;here&lt;/A&gt;. &amp;nbsp;Regex can be complicated, but they've been around for a long time (Perl uses them heavily), so for most things you can search the internet and find an example or two to base yours off of.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 15:36:38 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114840#M4689</guid>
      <dc:creator>asulliva</dc:creator>
      <dc:date>2016-01-20T15:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need tips to format output generated by PSTK cmlet Invoke-NaSsh</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114852#M4690</link>
      <description>&lt;P&gt;^^&lt;/P&gt;&lt;P&gt;Very nice explanation and tip... &amp;nbsp;Nice output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A quick way I do is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$v = Invoke-nassh "sp status"&lt;/P&gt;&lt;P&gt;$v = $v.split("`n")&lt;/P&gt;&lt;P&gt;$v | ? {$_ -like "*ip*"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 18:07:52 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Need-tips-to-format-output-generated-by-PSTK-cmlet-Invoke-NaSsh/m-p/114852#M4690</guid>
      <dc:creator>JGPSHNTAP</dc:creator>
      <dc:date>2016-01-20T18:07:52Z</dc:date>
    </item>
  </channel>
</rss>

