Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PowerShell Version
- #$PSVersionTable
- #Name Value
- #---- -----
- #PSVersion 4.0
- #WSManStackVersion 3.0
- #SerializationVersion 1.1.0.1
- #CLRVersion 4.0.30319.34209
- #BuildVersion 6.3.9600.17400
- #PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
- #PSRemotingProtocolVersion 2.2
- #Раздел с входными параметрами
- param(
- [string]$t
- )
- #Определяем глобальные переменные
- $fl_content_array=Get-Content .\GTS_LINUX-MULTI-001A.results #
- [array]$buf_array = @()
- [array]$output = @()
- #Функция разбора файла, ищем нужные метки, записываем нужные строки в массив, после чего передаём массив нужных строк во вне функции.
- function fl_to_arry {
- $fl_content_counter=0
- $fl_to_str_mark="false"
- $fl_to_str_start_num="null"
- [array]$str_array=@()
- $str_array_indx=0
- $fl_content_array| ForEach-Object -Process {
- if ($_ -contains "`[MEASURED_VALUE`]")
- {
- $fl_to_str_mark="true"
- $fl_to_str_start_num=$fl_content_counter
- }
- if ($_ -contains "`[MEASURED_VALUE_EOF`]")
- {
- $fl_to_str_mark="false"
- $fl_to_str_start_num=$fl_content_counter
- }
- if ($fl_to_str_mark -eq "true" -and $fl_to_str_start_num -ne $fl_content_counter)
- {
- $str_array += $_
- $str_array_indx++
- }
- $fl_content_counter++
- }
- return $str_array
- }
- #Функция разбора переданного fl_to_arry массива строк. Проверяем подстроки на метки директорий, линков, файлов терминалов, обычных файлов и дёргаем то что нужно на запись в массив на вывод.
- function array_to_output ([string]$ato_type, [array]$ato_str_array)
- {
- [array]$ato_unm_grp = New-Object 'object[,]' 4,5
- if ($ato_type -match "d")
- {
- $ato_str_array| ForEach-Object -Process {
- if ($_ -match "dr")
- {
- $ato_str="$_" -split ";"
- $usrname=$ato_str[1]
- $groupname=$ato_str[2]
- $ato_unm_grp += ,@($usrname,$groupname)
- }
- }
- }
- elseif ($ato_type -match "f")
- {
- $ato_str_array| ForEach-Object -Process {
- if ($_ -match "-r" -and $_ -notmatch "cr" -and $_ -notmatch "lr")
- {
- $ato_str="$_" -split ";"
- $usrname=$ato_str[1]
- $groupname=$ato_str[2]
- $ato_unm_grp += ,@($usrname,$groupname)
- }
- }
- }
- else
- {
- $ato_str_array| ForEach-Object -Process {
- $ato_str="$_" -split ";"
- $usrname=$ato_str[1]
- $groupname=$ato_str[2]
- $ato_unm_grp += ,@($usrname,$groupname)
- }
- }
- $out=$ato_unm_grp | sort-object | Get-Unique -AsString
- return $out
- }
- #Блок вызова функций и обработки их вывода.
- $buf_array=fl_to_arry
- $output=array_to_output $t $buf_array
- if ($t -match "d")
- {
- Write-Host "Output Filtered by directory"
- $output| foreach -Process {
- Write-Host $_
- }
- }
- elseif ($t -match "f")
- {
- Write-Host "Output Filtered by file"
- $output| foreach -Process {
- Write-Host $_
- }
- }
- else
- {
- $t="a"
- Write-Host "Output not filtered"
- $output| foreach -Process {
- Write-Host $_
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement