Anda di halaman 1dari 14

Use of PowerShell Scripting to

Automate Engineering Tasks


Nilesh Chordiya
What is PowerShell
PowerShell is a command line scripting
language similar to Unix language

How it is helpful to automate
engineering tasks
PowerShell script is useful to automate engineering task
like validation, reporting and extract required information
from set of files.
Below are some requirements can be achieved by
PowerShell Scripting
Extract and Save individual module FHX files from consolidated
FHX file
Extract module wise exposed parameter list
Extract Module Details like description, FP/DT name and so on..
Convert html to docx
Search and report http or www references from html pages


Pre-Requisites
Windows 7 or Higher Version of Windows Operating
System installed with
PowerShell 3.0 or Microsoft Windows
Management Framework (WMF) 3.0 (KB2506143)
http://www.microsoft.com/en-
in/download/details.aspx?id=34595
Installed .Net Framework 4.0 Client Profile
http://www.microsoft.com/en-
in/download/details.aspx?id=24872
FHX Processing Extract and Save
##############################################################
#
# NAME: Extract_n_Save_Individial_Module_Details_from_FHX
#
# AUTHOR: Nilesh.Chordiya
#
# COMMENT:
#
# VERSION HISTORY:
# 1.0 29-08-2013 - Initial release
# 1.1 20-09-2013 - Updated for speed up the performance
##############################################################
User Interface
Output Files
Module Validation and Reporting
############################################################
#
# NAME: Get Module Data from FHX file for validation purpose
#
# AUTHOR: Nilesh.Chordiya
#
# COMMENT:
#
# VERSION HISTORY:
# 1.0 25-02-2013 - Initial release
# 2.0 25-03-2013 - Changed for reporting PCSD Version information
#
############################################################
Output Report
PCSD_Lib_20130829_v12a.fhx
FUNCTION_BLOCK_DEFINITION
NAME= C_CNL_WT120

CATEGORY=
Library/CompositeTe
mplates/PCSD_Batch
_Miscellaneous DESCRIPTION=
PCSD Operator / Supervisor Cancel
Wait Composite V12.0.0
FUNCTION_BLOCK_DEFINITION
NAME= C_H_MON120

CATEGORY=
Library/CompositeTe
mplates/PCSD_Batch
_Miscellaneous DESCRIPTION=
PCSD Process Failure Monitor
Composite V12.0.0
FUNCTION_BLOCK_DEFINITION
NAME=
C_OAR_ENG_P
H120

CATEGORY=
Library/CompositeTe
mplates/PCSD_Batch
_Miscellaneous DESCRIPTION=
PCSD Composite for Operator
Action Request V12.0.0
Search Filename and Move to
Respective Folder
########################################################
# NAME: Search file in folder and Move file to respective folder
#
# AUTHOR: Nilesh.Chordiya
#
# COMMENT:
#
# VERSION HISTORY:
# 1.0 29-08-2013 - Initial release
#
#######################################################
Search a Specific Text in Files and
Move to Specific Folder
select-string -path *.fhx -pattern
"DESCRIPTION=`"PCSD", "PMO Configuration
Standard for DeltaV" -List | move-item -
Destination 'D:\Assignments\V12a Version
Update\v12a embedded
Where
"DESCRIPTION=`"PCSD", "PMO Configuration Standard for
DeltaV" is specific text to be search
-path *.fhx means search in current folder path
Destination 'D:\Assignments\V12a is a destination folder
path
Extract Module Exposed Parameter
List from FHX
Extract WWW and HTTP references
from HTML Documentation
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$path = Get-ScriptDirectory
$files = get-childitem -path $path -include *.htm -rec
$validatepattern = "href=`"http"
$validatepattern2 = "href=`"ftp"
[String[]] $FileOut = @()
foreach ($file in $files)
{
$cnt = 0
Foreach ($Line in [System.IO.File]::ReadLines($file))
{
$cnt = $cnt + 1
If (($Line -match $validatepattern) -or ($Line -match $validatepattern2))
{
$FileOut += $file.name
$FileOut += $Line
write-host $cnt -> $Line
}
}
}
$outfilepath = $path + "\www_http_reference_list.txt"
out-file -filepath $outfilepath -inputobject $FileOut
Convert html pages to Word
Document (Docx)

Anda mungkin juga menyukai