From 0c609d72aac52ca690771c1bcb5735bb8e615211 Mon Sep 17 00:00:00 2001 From: Jonathan Rioux Date: Thu, 25 Oct 2018 09:52:13 -0400 Subject: [PATCH] release 1.0.6 --- .gitignore | 3 +- Functions/ConvertTo-Array.psm1 | 87 ++++++++++++++++++++------ Functions/Get-SQLRestoreSessions.psm1 | 7 ++- PowerDP.psd1 | Bin 8568 -> 8584 bytes README.md | 46 +++++++++----- 5 files changed, 104 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index e451c28..4e306c8 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,5 @@ pip-log.txt build.ps1 *.sublime-project *.sublime-workspace -tmp \ No newline at end of file +tmp +README.html diff --git a/Functions/ConvertTo-Array.psm1 b/Functions/ConvertTo-Array.psm1 index 72b6d0b..fac4716 100644 --- a/Functions/ConvertTo-Array.psm1 +++ b/Functions/ConvertTo-Array.psm1 @@ -16,16 +16,26 @@ Function ConvertTo-Array { [CmdletBinding()] Param( [Parameter(ValueFromPipeline = $true)] - [ValidateNotNullOrEmpty()] [string[]]$Lines ) BEGIN { + $ConvertFrom = "" $Headers = $False $ArrayOutput = @() $i = 0 } PROCESS { $Lines | ForEach-Object { + #Detect type of input + if($ConvertFrom -eq ""){ + if($_.Startswith("#")){ + $ConvertFrom = "tab" + } else { + $ConvertFrom = "notab" + } + } + + $StartTime, $EndTime, $Time = $null #skip line if null or empty @@ -34,27 +44,62 @@ Function ConvertTo-Array { $ArrLine = @() $Item = New-Object PSObject $i++ - #skips lines until at the headers line - if($_.StartsWith("#")){ - #if current line contains the headers - if($Headers -eq $True){ - $Headers = $_.replace("# ","") - $Headers = $Headers.split("`t") + + + if($ConvertFrom -eq "tab"){ + + #skips lines until at the headers line + if($_.StartsWith("#")){ + #if current line contains the headers + if($Headers -eq $True){ + $Headers = $_.replace("# ","") + $Headers = $Headers.split("`t") + return + } + #if the next line contains the headers + if($_.StartsWith("# Headers")){ + $Headers = $True + return + } + return + #exit if unable to fetch the headers + } elseif($Headers -eq $False -or $Headers.Count -eq 0) { + Write-Error "Failed to fetch the headers from the input." + break + } + + $ArrLine = $_.split("`t") + + } else { + + #Skip if delimiter line + if($_ -match "^(={3,}|-{3,}|_{3,})" -or [string]::IsNullOrEmpty($_)){ return } - #if the next line contains the headers - if($_.StartsWith("# Headers")){ - $Headers = $True + + #Parse line with pattern + $line = $_ | Select-String -Pattern "\s*(.*?)(?:\s{2,}|$)" -AllMatches + + #Skip if invalid line + if($line.Matches.count -lt 3){ return } - return - #exit if unable to fetch the headers - } elseif($Headers -eq $False -or $Headers.Count -eq 0) { - Write-Error "Failed to fetch the headers from the input. Make sure you use the '-tab' parameter with the omnirpt command." - break + + #Convert the line to an array + Foreach($match in $line.Matches) { + if(![string]::IsNullOrEmpty($match.Groups[1].Value)){ + $ArrLine += $match.Groups[1].Value + } + } + + #Grab the headers + if($Headers -eq $false){ + $Headers = $ArrLine + return + } + + } - - $ArrLine = $_.split("`t") 0..($Headers.count-1) | ForEach-Object { if($Headers[$_] -match '^.*_t'){ @@ -68,8 +113,14 @@ Function ConvertTo-Array { } elseif($Headers[$_+1] -match '^.*_t') { return } elseif($Headers[$_] -match '^Duration.*') { - if($StartTime -ne $null -and $EndTime -ne $null){ + + #If job is not ended yet, we set the Duration to null + if($StartTime -gt $EndTime){ + $Duration = $null + + } elseif($StartTime -ne $null -and $EndTime -ne $null){ $Duration = [TimeSpan]::Parse($EndTime - $StartTime) + } else { try { $Duration = [TimeSpan]::Parse($ArrLine[$_]) diff --git a/Functions/Get-SQLRestoreSessions.psm1 b/Functions/Get-SQLRestoreSessions.psm1 index a26af4f..5fe89fa 100644 --- a/Functions/Get-SQLRestoreSessions.psm1 +++ b/Functions/Get-SQLRestoreSessions.psm1 @@ -1,9 +1,9 @@ Function Get-SQLRestoreSessions { <# .SYNOPSIS - Returns a table with latest SQL restore sessions + Returns an array with latest SQL restore sessions .DESCRIPTION - Fetches the session messages of each SQL restore sessions and creates a PowerShell table + Fetches the session messages of each SQL restore sessions and returns a PowerShell array .EXAMPLE Get-SQLRestoreSessions -Days 2 .LINK @@ -66,12 +66,13 @@ Function Get-SQLRestoreSessions { $Item | Add-Member -type NoteProperty -Name Source -Value $Source $Item | Add-Member -type NoteProperty -Name Target -Value $Target $Item | Add-Member -type NoteProperty -Name StartTime -Value $StartTime + $Item | Add-Member -type NoteProperty -Name EndTime -Value $EndTime $Item | Add-Member -type NoteProperty -Name Duration -Value $Duration $Item | Add-Member -type NoteProperty -Name Status -Value $Status $Item | Add-Member -type NoteProperty -Name SessionID -Value $SessionID $Array += $Item } else { - write-host "Erreur" + Write-Error "Cannot parse line: $_" return } } diff --git a/PowerDP.psd1 b/PowerDP.psd1 index 054b395cc8431f9bd436afa9880137eafd33f932..4b8c451f156ff3d1fab85b51708fcaa4fc928ff6 100644 GIT binary patch delta 130 zcmez2)Zskg9H$|J0fR1s5rgT*>%okSW|Os<9=lrr`6dj;42BFz42cZpVEI&rRG_FX zP&|>rlpzhsN&<>l0@dgORVD*@rVJ@S+7hT9q#sCc4rNYe67^-s1PT{1%okSrjxaq9=jVbm@=d>m@}9G#myKjf$~W}Ri+H7 zK$Z!RG=hqyFr)z0=`vUV -tab` output into a PowerShell array for easy filtering and manipulation. I intent to develop other functions in the future that builds on top of that. +> #### by Jonathan Rioux +> ***Note*** This module is NOT affiliated with, funded, or in any way associated with Micro Focus. -***Note*** This module is NOT affiliated with, funded, or in any way associated with HPE. +PowerShell for Micro Focus Data Protector (DP) +- +This PowerShell Module converts the `omnirpt <...> -tab` output into a PowerShell array for easy filtering and manipulation. It also provides a few functions that outputs native PowerShell arrays. I intent to develop other functions in the future that builds on top of that. Installation - @@ -19,44 +20,55 @@ Get [PowerShellGet Module](https://docs.microsoft.com/en-us/powershell/gallery/p Usage - -The main function is `ConvertTo-Array`. You can pipline the output from the `omnirpt` command or pass it as a parameter. ```PowerShell +#The main function is `ConvertTo-Array`. You can pipline the output from the `omnirpt` command or pass it as a parameter. +#The column names are kept the same, so you can easily filter with the columns names and display only the columns you want. +#It's important to include the `-tab` parameter because the function needs the input to be tab separated. omnirpt -report list_sessions -timeframe 24 24 -tab | ConvertTo-Array - omnirpt -report used_media -timeframe 48 48 -tab | ConvertTo-Array | Where-Object {$_.Location -like "*HP:MSL6480*"} -``` -There is also ready-to-use functions to generate reports in PowerShell array format. -```PowerShell +#Converts the list_sessions report to a PowerShell array Get-ListSessions | Out-GridView - Get-ListSessions -Specification *full* -Days 7 -SessionType backup - Get-ListSessions -Specification *sql* -Hours 4 -Mode trans -``` -The column names are kept the same, so you can easily filter with the columns names and display only the columns you want. It's important to include the `-tab` parameter because the function needs the input to be tab separated. +#Converts the session_objects report to a PowerShell array +Get-SessionObjects 2018/03/30-01 + +#Fetches the session messages of each SQL restore sessions and returns a PowerShell array +Get-SQLRestoreSessions -Days 2 +``` Prerequisites - PowerDP requires `omniback` to be installed, and its `bin` directory must be in the PATH environment variable. You can install the `User Interface` component on your workstation if you want to use PowerDP on your workstation. To do so, add your workstation as a Client in the CM and install only the `User Interface` component. +Compatibility +- +Confirmed working on DP versions 10.00 and up. + Release notes - -#### 1.0.5 +#### 1.0.6 (October 25, 2018) +* Bugfix: The Duration and EndTime fields now shows *null* when the job has not ended yet +* Since DP is now owned by Micro Focus, I changed the title of the module accordingly + +#### 1.0.5 (April 20, 2018) * Converts string numbers to Int to allow sorting * Some bugfix -#### 1.0.4 + +#### 1.0.4 (April 3, 2018) * Added new function : Get-SessionObjects * Enhanced function ConvertTo-Array - Removed "[" and "]" in column names so they are displayed correctly in Out-GridView - "Duration" column now displays with seconds - Converts the "Size [kB]" column to "Size (GB)" for better readability of the size -#### 1.0.3 + +#### 1.0.3 (March 22, 2018) * Added new function : Get-ListSessions * Removed "\_t" (timestamp) column and keep only the non-"\_t" column since its already converted to DateTime format * Some code optimization -#### 1.0.2 +#### 1.0.2 (March 21, 2018) * Initial stable release \ No newline at end of file