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

 


6 comments:

clasesofproessioanl said...

Hey ,

Great Job . You Know what ?

I read a lot of blog posts and I never heard of such a topic. I love the subject you have done about bloggers. Very simple. I am also writing a blog related to the Germany job seeking visa. You can also see this.

clasesofproessioanl said...

Good post, and thanks for sharing such an adorable post. I would love to see more articles / blogs. I am also writing about Personality Development Courses For Kids

QuickBooks Customer Service said...

Hi,
If you have any issues related to QuickBooks like
Download QuickBooks File Doctor
QuickBooks Statement Writer Issues
QuickBooks Error Code C=44
QuickBooks Error Code 64
QuickBooks Error Code 7300
or any other QuickBooks issues then contact our support team to resolve your issues within time.

Hussain Ahmad said...

I was more than happy to uncover this great site. I need to thank you for your time due to this fantastic read!!
I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
humidifier dehumidifier combo

Hussain Ahmad said...

I was more than happy to uncover this great site. I need to thank you for your time due to this fantastic read!!
I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
WordPress Chat Plugin

Amara Garcia said...

Thanks for sharing this blog.
If you install Norton 360 Antivirus and you face issue then click here to know How to Install Norton 360 Antivirus easily without any help.