TEXT

Sunday, March 7, 2021

Simplifying getting a summary for your scripts.

  

Simplifying getting a summary for your scripts. I will assume you are writing script often and you want to be more organized with your scripts. When writing script it is always a good idea to make sure you have enough information about your code. Following example will demonstrate same end goal. in the example given below, when writing script within the scripts following notation is used.

#(1)_.Adding Vars

#(2)_.Check folder existence

#(3)_.Entering loop 

#(4)_.Setting counter 

after making sure script is built correctly , you can run below function to grab all lines includes pattern defined "#" and use can use it within the script to present summary information.

  


<#   

 

.NOTES

#------------------------------------------------------

# Script      : Untitled18.ps1

# Created     : ISE 3.0

# Author(s)   : (Casey.Dedeal)

# Date        : 03/07/2021 08:56:40

# Org         : CloudSec365

# File Name   : Untitled18.ps1

# Comments    : None

# Assumptions : None

#------------------------------------------------------

 

.SYNOPSIS     : Untitled18.ps1

.DESCRIPTION  : Following script,

.License      : Open license

.Limitations  : None

.Known issues : None

.Credits      : (Casey.Dedeal)

.Blog         : https://simplepowershell.blogspot.com

.Blog         : https://msazure365.blogspot.com

.Blog         : https://cloudsec365.blogspot.com

.Twitter      : https://twitter.com/Message_Talk

              

.EXAMPLE

 

  .\Get-Sample.ps1

  MAP:

-----------

 

#(1)_.Adding Vars

#(2)_.Check folder existence

#(3)_.Entering loop 

#(4)_.Setting counter 

 

-----------

 

   #>

 

 



function Function-Print-MAP {

[cmdletbinding()]

param(

    [parameter(

        Mandatory         = $true,

        ValueFromPipeline = $true)]

        [string]$Filepath,

        $pipelineInput

)

 

    Begin {      

    }

 

    Process {

Try{

 

     #(1)_.Check to make sure filepath exist

  If (!(Test-Path $Filepath)){

     Write-Host 'CANNOT locate file' -ForegroundColor White -BackgroundColor Red

     Write-Host 'Script will stop' -ForegroundColor Yellow

     break;

     }

     #(2)_.Catch pattern

     $pattern = "#"

     $report = get-content $filePath -ReadCount 1000 | foreach { $_ -match $pattern }

     $report | Foreach {$_.TrimEnd()}

     $report

     $report | Out-GridView

 

  }Catch{

 

  $errofile = $($PSItem.ToString())

  Write-Warning 'Error has occoured'

  Write-host 'Problem FOUND' $errofile -ForegroundColor red -BackgroundColor Black

 

               }

    

           }

 

    End {

 

    }

 

}

 

 

$filepath = "C:\TEMP\KFM-SET-Health-CHECK-V1.ps1"

Function-Print-MAP -Filepath $filepath

 

 

 

Azure Solutions Architect
AWS Certified Cloud Practitioner
Azure Certified Security Engineer Associate
https://simplepowershell.blogspot.com
https://cloudsec365.blogspot.com
https://msazure365.blogspot.com
https://twitter.com/Message_Talk

 


No comments:

Post a Comment

Simple Function Do Something

   Use template below to create simple PS function    # Simple Function Do Something # Change $ReportName   function Fu...