6 Replies Latest reply on Jan 12, 2017 4:06 PM by rsun

    Queries related to Start-PIArchiveReporcess

    Paurav Joshi

      Hello Folks,

       

      We have Start-PIArchiveReprocess PowerShell command available from SMT 2016 R2. Neither in document nor in PowerShell (Get-Help Start-PIArchiveReprocess) I can find example of this command. If fellows can provide it here, it will be useful .

       

      I have PI SMT 2016 R2 PowerShell portion installed and have PowerShell Version 3.0 . Will this command work in only PowerShell 4.0 environment? (because I am unable to find help information in version 3.0)

       

      Can anyone provide steps to do archive reprocess using PowerShell without this command so that I can use in PowerShell 3.0 (Upgrade to Version 4.0 can't be done, so kindly move to next suggestions ) ?

       

      Thanks,

      Paurav Joshi

        • Re: Queries related to Start-PIArchiveReporcess
          gregor

          Hello Paurav,

           

          You found the documentation for module OSIsoft.PowerShell already at Live Library. Unfortunately none of my VM's nor my Laptop has PowerShell 3.0 and I can't locate any information related to the minimum PowerShell version.

          As far as I can see Windows 8.1 and Windows 2012 R2 Server machines have version 4.0 and Windows 10 and Windows Server 2016 even report version 5.1

           

          Have you tried the Get-Help command?

           

          Get-Help Start-PIArchiveReprocess
          
          • Re: Queries related to Start-PIArchiveReporcess
            rsun

            PI SMT also offer Reprocess Archive capability. Is it something you would consider using?

            Capture.JPG

            • Re: Queries related to Start-PIArchiveReporcess
              Paurav Joshi

              Hello Folks,

               

              My bad. We can check all commands of module via

              Get-Command -Module OSIsoft.PowerShell
              

               

              So this reprocess command is not available in PowerShell Version 3.0.

               

              Boiled down to question, with PowerShell Version 3.0 how can we automate reprocessing of PI Archives ?

               

              Still adding examples of reprocess command into document or here will help in future .

               

              Thanks,

              Paurav Joshi

                • Re: Queries related to Start-PIArchiveReporcess
                  rsun

                  The other option is to use offline archive utility and then integrate it with powershell.

                  Please see below for example code:

                   

                  ########################################################################
                  ########################################################################
                  ##
                  ## Reprocess-Archives
                  ##
                  ##
                  ##
                  ##
                  ########################################################################
                  ########################################################################
                  
                  
                  ## Takes a string and prints a formatted message to the powershell window
                  function Print-Message([String]$message = "", [int]$type = 0)
                  {
                    ## Message format
                    $output = "{0:HH:mm:ss} --- {1}" -f [DateTime]::Now, $message
                  
                    ## Check the severity of the message
                    switch($type)
                    {
                    0 { Write-Host $output -ForegroundColor White }
                    1 { Write-Host $output -ForegroundColor Yellow }
                    2 { Write-Host $output -ForegroundColor Red }
                    3 { Write-Host $output -ForegroundColor Green }
                    default { Write-Host $output -ForegroundColor White }
                    }
                  }
                  
                  
                  ## Checks for the essential binaries need for operation
                  function Find-Utilities
                  {
                    ## Check the pi server directory
                    if([String]::IsNullOrEmpty($Env:PIServer) -or !(Test-Path $Env:PIServer -PathType Container))
                    {
                    Print-Message "ERROR! Invalid path for PI Server directory, exiting" 2
                    return
                    }
                  
                    ## Check for piartool
                    $global:piartool = "$Env:PIServer\adm\piartool.exe"
                    if(!(Test-Path $global:piartool -PathType Leaf))
                    {
                    Print-Message "ERROR! Piartool not found, exiting" 2
                    return
                    }
                  
                    ## Check for piarchss
                    $global:piarchss = "$Env:PIServer\bin\piarchss.exe"
                    if(!(Test-Path $global:piarchss -PathType Leaf))
                    {
                    Print-Message "ERROR! Piarchss not found, exiting" 2
                    return
                    }
                  }
                  
                  
                  ## Takes an array of archive files and unregisters them
                  function Find-Archives([String[]]$archives = @())
                  {
                    Write-Host ""
                    Print-Message "Determining Archive Subsystem availability" 0
                    ## Make sure archive is responsive
                    Ping-Archive | Out-File $global:logFile -Append
                    if($LASTEXITCODE -ne 0)
                    {
                    Print-Message "ERROR! Piarchss took over 10 seconds to respond, exiting" 2
                    return
                    }
                  
                    $validatedArchives = @()
                    Print-Message "Validating archive file paths" 0
                    ## Go through the archives
                    foreach($archive in $archives)
                    {
                    ## Check if the file exists
                    if(!(Test-Path $archive -PathType Leaf))
                    {
                    Print-Message "WARNING! Invalid path for $archive, excluding" 1
                    continue
                    }
                  
                    ## Try to unregister the archive
                    Print-Message "Unregistering $archive" 0
                    Unregister-Archive $archive | Out-File $global:logFile -Append
                    if($LASTEXITCODE -eq 0)
                    {
                    $validatedArchives += $archive
                    Print-Message "SUCCESS! $archive now offline" 3
                    }
                    else
                    {
                    Print-Message "WARNING! Failed to unregister $archive, excluding" 1
                    }
                    }
                  
                    ## Returns a list of archives that could be unregistered
                    return $validatedArchives
                  }
                  
                  
                  ## Checks archive responsiveness
                  function Ping-Archive
                  {
                    &$global:piartool -block piarchss 10 -verbose
                  }
                  
                  
                  ## Unregisters an archive file
                  function Unregister-Archive([String]$archivePath = "\")
                  {
                    &$global:piartool -au "$archivePath"
                  }
                  
                  
                  ## Registers an archive file
                  function Register-Archive([String]$archivePath = "\")
                  {
                    &$global:piartool -ar "$archivePath"
                  }
                  
                  
                  ## Takes an archive file and reprocesses it
                  function Process-Archive([String]$archivePath = "\")
                  {
                    ## setup the parameters
                    $theArgs = '-if "' + $archivePath + '" -of "' + $archivePath + '.repro"'
                    ## Launch the offline archive util
                    Start-Process -FilePath $global:piarchss -ArgumentList $theArgs -Wait -RedirectStandardOutput $global:currentLog
                  }
                  
                  
                  ## Goes through a list of archive files and reprocesses them
                  function Process-ArchiveList([String[]]$archives = @())
                  {
                    ## Make sure there are archives to reprocesses
                    if($archives.Count -le 0)
                    {
                    Print-Message "ERROR! No archives were unregistered, exiting" 2
                    return
                    }
                  
                  
                    ## Display the archives that are going to be reprocessed
                    Print-Message "Archives eligible for reprocessing:`n" 0
                    $archives
                    Write-Host ""
                    Print-Message "Archive reprocessing initiated" 0
                  
                    $global:currentLog = "CurrentReprocessingLog.txt"
                  
                    ## Loop through all the files
                    foreach($a in $archives)
                    {
                    Print-Message "Reprocessing $a (check $global:currentLog for progress)" 0
                    ## Reprocess the archive file
                    Process-Archive "$a"
                    ## Merge the reprocess log into the master log file
                    Get-Content "$global:currentLog" | Out-File $global:logFile -Append
                  
                    Print-Message "Registering $a.repro" 0
                    ## Try to register the new archive file
                    Register-Archive "$a.repro" | Out-File $global:logFile -Append
                    ## if we fail, try to roll back to the original file
                    if($LASTEXITCODE -ne 0)
                    {
                    Print-Message "WARNING! Could not register $a.repro, using original file" 1
                    ## Try to register the old archive file
                    Register-Archive "$a" | Out-File $global:logFile -Append
                    ## Rollback failed, exit
                    if($LASTEXITCODE -ne 0)
                    {
                    Print-Message "ERROR! Could not register original archive file, exiting" 2
                    return
                    }
                    }
                    else
                    {
                    Print-Message "SUCCESS! $a.repro now online" 3
                    }
                    }
                  
                    ## Remove the temp log
                    Remove-Item "$global:currentLog"
                    Print-Message "COMPLETE! Examine $global:logFile for details`n" 3
                  }
                  
                  
                  ## Takes a list of archive paths from the user and reprocesses them
                  function Get-List
                  {
                    ## Prompt the user for archive files
                    Write-Host "`nNOTE: Separate archives by comma, i.e. C:\arc1,C:\Program Files\arc2,etc" -ForegroundColor Yellow
                    [String[]]$archiveList = (Read-Host "Archives").Split(",") | % { $_.Trim() }
                  
                    ## make sure there are files in there
                    if($archiveList.Count -le 0)
                    {
                    Print-Message "ERROR! No files specified, exiting" 2
                    return
                    }
                  
                    ## Checks all the paths entered, and verifies they are archive files
                    [String[]] $foundArchives = Find-Archives $archiveList
                    ## Reprocesses all of the archive files
                    Process-ArchiveList $foundArchives
                  }
                  
                  
                  ## Takes a directory path and processes all of the archive files therein
                  function Get-Directory
                  {
                    Write-Host "`nNOTE: Omit quotes, i.e. C:\Program Files\Archive Folder" -ForegroundColor Yellow
                    ## get the path
                    [String]$directory = Read-Host "Directory path"
                    ## make sure it is a directory
                    if(!(Test-Path $directory -PathType Container))
                    {
                    Print-Message "ERROR! Invalid directory path $directory, exiting" 2
                    return
                    }
                  
                    ## grab all the archive paths
                    [String[]] $archiveList = Get-ChildItem "$directory" | Where-Object { !($_.psiscontainer) -and $_.Extension -ne '.ann'} | Select fullname | Foreach { $_.FullName }
                  
                    ## make sure there are files in there
                    if($archiveList.Count -le 0)
                    {
                    Print-Message "ERROR! No files in specified directory, exiting" 2
                    return
                    }
                  
                    ## make sure these are archive files
                    [String[]] $foundArchives = Find-Archives $archiveList
                    ## reprocess the entire list
                    Process-ArchiveList $foundArchives
                  }
                  
                  
                  ## Prints out the menu options, and takes a selection from the user
                  function Get-Menu
                  {
                    [Management.Automation.Host.ChoiceDescription[]] $choices = @()
                    $options = "&List of Archives",
                    "&Directory of Archives",
                    "&Quit"
                    $helpText = "Reprocesses a given list of archive files",
                    "Reprocesses an entire directory of archive files",
                    "Quits the script"
                    $caption = "What do you want to reprocess?"
                    $default = 2
                  
                    for($item = 0; $item -lt $options.Length; $item++)
                    {
                    $choice = New-Object Management.Automation.Host.ChoiceDescription $options[$item]
                    if($helpText -and $helpText[$item])
                    {
                    $choice.HelpMessage = $helpText[$item]
                    }
                  
                    $choices += $choice
                    }
                  
                    do
                    {
                    $result = $host.UI.PromptForChoice($caption, "`n", $choices, $default)
                    switch($result)
                    {
                    0 { Get-List; $result = 2; break }
                    1 { Get-Directory; $result = 2; break }
                    default { $result = 2 }
                    }
                    } while ($result -ne 2)
                  }
                  
                  ## Main function, launches the menu
                  function Main
                  {
                    ## sets a reference to our log file
                    $global:logFile = "MasterReprocessingLog.txt"
                    ## don't start until we verify the prereq utils
                    Find-Utilities
                    ## display the menu
                    Get-Menu
                  }
                  
                  
                  ## Calls main to start the script
                  Main