JanaBala@5

Re-Process Primary Archive (powershell Script)

Discussion created by JanaBala@5 on Jun 4, 2017
Latest reply on Jun 5, 2017 by JanaBala@5

Hi

 

this script will reprocess primary archive and save the old archive to the same folder.

 

In this powershell script, I have hard corded the %piserver% Path, Please change it.

 

Save this script as powershell ext (*.ps1).

 

script:

============================================================================================================================================

 

#Check PI Archive Subsystem Status

$ServiceName = 'PI Archive Subsystem'

$arrService = Get-Service -Name $ServiceName

$ASSstsus = $arrService.Status

"PI Archive Subsystem Status = " + $ASSstsus

 

if ($arrService -ne 'Running') {break}

 

else

{

 

<# get local server name #>

$server_name = $env:computername

"Local PI Server Name = " + $server_name

 

<# Connect to local PI server #>

$myPI = Connect-PIDataArchive -PIDataArchiveMachineName $server_name

 

<# Get primary archive file name #>

$archivefilename = Get-PIArchiveFileInfo -Connection $myPiI-id 0

$Arcfilename1 = $archivefilename.path

"Arcfilename1 = " + $Arcfilename1

$Arcfilename2 = $Arcfilename1.TrimEnd(".arc")

"Arcfilename2 = " + $Arcfilename2

 

<# Fixing the Fie name #>

Set-Item -path env:Path -value "D:\Program Files\PI\bin"

$piarcpath = 'piarchss.exe'

$app = 'D:\Program Files\PI\bin\piarchss.exe'

 

$old = "_OLD"

$arc = ".arc"

$ann = ".arc.ann"

$fixed = "_Fixed"

$fixedfilename = $Arcfilename2 + $fixed + $arc

$fixedfilenameann = $Arcfilename2 + $fixed + $ann

$Oldfilename = $Arcfilename2 + $old + $arc

$Oldfilenameann = $Arcfilename2 + $old + $ann

$Arcfilename2ann = $Arcfilename2 + $ann

 

"fixedfilename = " + $fixedfilename

"fixedfilenameann = " + $fixedfilenameann

" Oldfilename = " + $Oldfilename

"Oldfilenameann = " + $Oldfilenameann

"Arcfilename2ann = " + $Arcfilename2ann

 

<# Reprocess primary Archive file #>

<# %piserver%\bin\piarchss.exe -if $currentarchive -of $temparchive -f 0 -oet primary -noinputcheck #>

$repeprocesscmd = " -if " + $Arcfilename1 + " -of " + $fixedfilename + " -f 0 -oet primary -noinputcheck"

 

"repeprocesscmd = " + $repeprocesscmd

 

 

 

write-host "Stopping ---PI Archive Subsystem Service---"

Start-Sleep -s 5

 

# Stop "PI Archive Subsystem" Service

Stop-Service -displayname "PI Archive Subsystem"

 

write-host "Ready to Reprocess Primary Archive..."

Start-Sleep -s 5

 

start-process -filepath $app -Argumentlist $repeprocesscmd -wait

 

write-host "Ready to Rename and Mount Primary Archive..."

Start-Sleep -s 5

 

 

# Rename Archive files

rename-item -path $arcfilename1 -newname $Oldfilename

rename-item -path $arcfilename2ann -newname $Oldfilenameann

rename-item -path $fixedfilename -newnwme $Arcfilename1

rename-item -paht $fixedfilenameann -NewName $Arcfilename2ann

 

write-host "Starting ---PI Archive Subsystem Service---"

 

 

# Start "PI Archive Subsystem" Service

Start-Service -displayname "PI Archive Subsystem"

Start-Sleep -s 5

}

 

=================================================================================================

Outcomes