Skip to content

Commit

Permalink
release 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jorioux committed Oct 25, 2018
1 parent a795a80 commit 0c609d7
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ pip-log.txt
build.ps1
*.sublime-project
*.sublime-workspace
tmp
tmp
README.html
87 changes: 69 additions & 18 deletions Functions/ConvertTo-Array.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'){
Expand All @@ -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[$_])
Expand Down
7 changes: 4 additions & 3 deletions Functions/Get-SQLRestoreSessions.psm1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
Binary file modified PowerDP.psd1
Binary file not shown.
46 changes: 29 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# PowerDP
PowerShell for HPE Data Protector (DP)
-
This PowerShell Module converts the `omnirpt <...> -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
-
Expand All @@ -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

0 comments on commit 0c609d7

Please sign in to comment.