Pages

Friday, September 6, 2019

Regular Expression ready reference


RegEx

Description

.

matches any character except newline

\

escape character

\w

word character [a-zA-Z_0-9]

\W

non-word character [^a-zA-Z_0-9]

\d

Digit [0-9]

\D

non-digit [^0-9]

\n

new line

\r

carriage return

\t

tabulation

\s

white space

\S

non-white space

^

beginning of a line

$

end of a line

\A

beginning of the string (multi-line match)

\Z

end of the string (multi-line match)

\b

word boundary, boundary between \w and \W

\B

not a word boundary

\<

beginning of a word

\>

end of a word

{n}

matches exaclty n times

{n,}

matches a minimum of n times

{x,y}

matches a min of x and max of y

(a|b)

‘a’ or ‘b’

*

matches 0 or more times

+

matches 1 or more times

?

matches 1 or 0 times

*?

matches 0 or more times, but as few as possible

+?

matches 1 or more times, but as few as possible

??

matches 0 or 1 time

[abc]

a single character of: a, b, or c

[^abc]

any single character except: a, b, or c

[a-z]

any single character in the range a-z

[a-zA-Z]

any single character in the range a-z or A-Z

(…)

capture everything enclosed

a?

zero or one of a

a*

zero or more of a

a+

one or more of a

a{3}

exactly 3 of a

a{3,}

3 or more of a

a{3,6}

between 3 and 6 of a

 

Tuesday, January 8, 2019

Multipath information from Windows servers running with HDLM


Multipath information from Windows servers running with HDLM

Here is a Script developed in PowerShell to retrieve Multipath information from Windows servers running with HDLM DSM as MPIO.

This script can be used without any parameter to present useful and minimal required information.
There are different parameters which can be used to retrieve maximum possible information from servers but they are in raw format (text format)

This script can also be downloaded from Microsoft Technet Script Gallery
https://gallery.technet.microsoft.com/HDLM-Multipath-Information-003fdc80



# Developed for fetching Multipath Information from Windows servers running with HDLM MPIO
# If used without any parameter, it will display information in simple way by processing information retrieved from HDLM binaries.
# There are three parameters defined in the script which can be used to get different type of information related to Multipathing
# Information retrieved with defined parameters are only raw (Plain Text) and needs to be interpreted properly.
# Use it at your own responsibility Developer will not be held responsible for any damage caused by running this script improperly.
# Developed on Jan-08-2019

Param(
  [Switch]$Verbose,
  [Switch]$PathOnly,
  [Switch]$Compact
)
if ($PathOnly )
    {
        dlnkmgr view -path -c
    }
elseif ($Verbose)
    {
        write-host "`n_________  Displaying HDLM agent Information _________`n"
            dlnkmgr view -sys
        write-host "`n__________    Displaying Luns Information    _________`n"
            dlnkmgr view -lu
        write-host "`n_________    Displaying Path Information     _________`n"
            dlnkmgr view -path
    }
elseif ($Compact)
    {
        write-host "`n_______________    Displaying HDLM Version    _______________`n"
            dlnkmgr view -sys |Select-String "HDLM Version"
        write-host "`n_________    Displaying Luns Information (Compact)   _________`n"
            dlnkmgr view -lu -c
        write-host "`n_________    Displaying Path Information (Compact)   _________`n"
            dlnkmgr view -path -c

    }
else
    {
## HDLM Version
    $HDLMVer = dlnkmgr view -sys |Select-String "HDLM Version"
    $HDLMVer = $HDLMVer -replace " ","" -split ":"
    $HDLMVersion = "HDLMVersion   :: $($HDLMVer[1])"
    $Computername = "Computername  :: $env:COMPUTERNAME"

##Fetch total Number of Luns
    $LunCount = dlnkmgr view -lu |Select-String "LUs"
    $Luns = $LunCount -replace " ","" -split ":"

 
##Online Paths Count
    $OnlinePaths = "OnlinePaths   :: $((dlnkmgr view -path |Select-String HITACHI |Select-String "online" |measure).Count)"

##Offline Paths Count
    $OfflineLuns = "OfflinePaths  :: $((dlnkmgr view -path |Select-String HITACHI |Select-String -NotMatch "online" |measure).Count)"

##First Line of "dlnkmgr view -lu -c" which contains Array Serial Number, first lun and its path details

    $Pathinfo = dlnkmgr view -lu -c | Select-String -notmatch "Product","HDLM command"
    $FirstLine = $Pathinfo -replace "\s{1,}",":" |select -First 1
    $info = ($firstline -split ":")

##Array Summary with Array Name, Array Serial Number and Total Number of Luns Presented
    $ArrayName = "ArrayName     :: $($info[0])"
    $ArraySerial = "ArraySerial   :: $($info[1])"
    $TotalLuns = "TotalLuns     :: $($info[2])"

##Print Summary
    Write-Output "------------------------------------------------------------------------------------------"
    Write-Output "----------------------------------     Host Summary        -------------------------------"
    Write-Output "------------------------------------------------------------------------------------------"
    $Computername, $TotalLuns, $OnlinePaths, $OfflineLuns, $HDLMVersion, $ArrayName, $ArraySerial

##First Lun Details
    $FirstLun = Write-Output "LunID :: $($info[3]) `t DriveLetter :: $($info[4])`t TotalPaths :: $($info[5])`t OnlinePaths :: $($info[6])"

##Remaining Lines of "dlnkmgr view -lu -c" which contains Array Serial Number, remaining luns and their path details
    $otherpaths = $Pathinfo -replace "\s{1,}",":" |select -Skip 1
    $otherinfo = ($otherpaths -split ":")
    $allPaths = $Pathinfo |select -Skip 1 | foreach {$_ -replace "\s{1,}",":"} |foreach { $_ -replace "^:" }

    $Remaining = $allPaths | foreach { $Line = $_ -split ":"; write-output  "LunID :: $($Line[0]) `t DriveLetter :: $($Line[1]) `t TotalPaths :: $($Line[2])`t OnlinePaths :: $($Line[3]) "}

    Write-Output "------------------------------------------------------------------------------------------"
    Write-Output "----------------------------------     LUNs Summary       --------------------------------"
    Write-Output "------------------------------------------------------------------------------------------"
    Write-Output $FirstLun
    Write-Output $Remaining
    }


Here are the screenshots taken from this script's execution:
 
Script executed without any parameter

 Script executed with parameter -PathOnly

Script executed with parameter -Compact

 Script executed with parameter -Verbose