Шаблон скрипта

#Требуем запуск от администратора 
#Requires -RunAsAdministrator   
 
#region Data input
 
$MyScriptRoot = Split-Path $script:MyInvocation.MyCommand.Path
$MyCSV        = "$MyScriptRoot\MyData.csv"
$MyHTML       = "$MyScriptRoot\MyData.html"
$MyList       = New-Object -TypeName System.Collections.ArrayList
 
$MyData = @'
1111111111111111111111
2222222222222222222222
2333333333333333333333
4444444444444444444444
5555555555555555555555 
'@ -split "`n" | ForEach-Object { $_.Trim() }| Where-Object { -not [string]::IsNullOrWhiteSpace($_ ) }
 
 
if (!(test-path -Path $MyCSV )){
 write-host -ForegroundColor Red "File $MyCSV not found!"
 break
}
 
$MyData = Import-CSV -Path  $MyCSV |
          Where-Object { $_.PSObject.Properties.Value -ne '' } |  #remove blank lines
          Where-Object {($_.fio).trim()}                          #remove trims from begin and end 
 
$MyHTMLData=@{
           body = "body"
           head = "header"
          title = "title"
     precontent = "precontent"
    postcontent = "postcontent"
         cssuri = "cssuri"
}
#endregion 
 
#region Обработка данных
 
foreach ($MyItem in $MyData)
{
   "|$myItem|" #Контроль вывода, потом можно удалить
 
    If ($MyItem -match  "^2"){
        [void]$MyList.Add( [pscustomobject] @{DATA1=$MyItem;DATA2=$Myitem - (get-random)}) 
    }
}
#endregion 
 
#region Вывод данных
 
$MyList
$MyList | Out-GridView
$MyList | export-csv -Path $MyCSV -Force -Encoding UTF8 -Delimiter ";" -NoTypeInformation
$MyList | ConvertTo-Html @MyHTMLData | Out-File  $MyHTML -Force -Encoding UTF8
 
psedit $MyCSV 
psedit $MyHTML 
#endregion
 
<#
    body        = "body"
    head        = "header"
    title       = "title"
    precontent  = "precontent"
    postcontent = "postcontent"
    cssuri      = "cssuri"
    fragment    = "fragment"
 
#>