Coder Social home page Coder Social logo

jm.scripttools's Introduction

🔧 JM.ScriptTools

Some PowerShell helpers functions to shorten and speed up console and scripts work.

Installation

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/Reyozam/JM.ScriptTools/master/InstallModule.ps1'))

Import-Module JM.ScriptTools

Functions

Write-Log

This function output formatted log event to console, logfile or both.

Write-Log -StartLog -LogFile $LogFile;
Write-Log -Level Info -Message "Info Log Example" -LogFile $LogFile;
Write-Log -Level Success -Message "Success Log Example" -LogFile $LogFile;
Write-Log -Level Warning -Message "Warning Log Example" -LogFile $LogFile;
Write-Log -Level Error -Message "Error Log Example" -LogFile $LogFile;
Write-Log -Level Info -Message "Send only to the console" -Tab 3;
Write-Log -EndLog -LogFile $LogFile

Write-Log

LogFile Output :
[10:02:05:155] [INFO   ] Info Log Example
[10:02:05:158] [SUCCESS] Success Log Example
[10:02:05:163] [WARNING] Warning Log Example
[10:02:05:167] [ERROR  ] Error Log Example

Out-HTMLReport

This function can generate conditional formatted HTML Table to build some fancy report.

$Service_Conditions = @{
    name       = "Status"
    expression = { $_.Status }
    css        = { if ($_.Status -eq "Stopped") { 'red' } else { 'green' } }
}

$Process_Conditions = @{
    name       = "Cpu"
    expression = { $_.cpu }
    css        = { if ($_.cpu -gt 7000) { 'red' } elseif ($_.cpu -gt 5000) { 'orange' } else {"green"} }
}

$FragmentsService = Get-Service | Select-object -first 10  | Out-HTMLReportFragment -PreContent "Service" -Properties name,$Service_Conditions

$FragmentProcess = Get-Process | Sort-Object cpu -Descending | Select-Object -first 10 | Out-HTMLReportFragment -PreContent "Process" -Properties name,$Process_Conditions

$HTMLCode = Out-HTMLReport -HTMLFragments $FragmentsService,$FragmentProcess -Title "Report" -PreContent "Services & Process" | Out-File $env:USERPROFILE\Desktop\TestHTML.html

Write-Log

Write-ProgressBar

This function output a CLI progress bar in the console

for ($i = 0; $i -lt 100; $i++) {
 Write-ProgressBar -Activity "Job Running ..." -Progress $i
}

Write-Log

Send-Notification

This function can trigger Windows Pop-up Notification

Send-Notification -Title "Finish" -Message "Your script has done his job" -BalloonIcon Info

Write-Log

Invoke-MessageBox

This function will show customizable GUI Message Box

Invoke-MessageBox "Do you want to continue" -Buttons YesNo -Title "Confim ?" -Icon Warning

Write-Log

Invoke-InputBox

This function will show customizable GUI Input Box

Invoke-InputBox -Title "User Input" -Message "Enter your username:"
Invoke-InputBox -Title "User Input" -Message "Enter your password:" -AsSecureString

Write-Log

Write-Log

Out-TableColor

This function output conditional formatted object

Get-Service | Out-TableColor -PropertyConditions @{"Stopped"="red";"Running"="green"} -Property status

Write-Log

Write-Menu

This function show menu from an hashtable template

$Menu = @{

    Title = "Menu Title"

    "1"   = @{
        Label  = "Option 1"
        Action = { Write-Host "You choose Option 1" }
    }

    "2"   = @{
        Label  = "Option 2"
        Action = { Write-Host "You choose Option 2" }
    }

}

Write-Menu -MenuHashtable $Menu

Write-Log

Get-RunInfo

This function output some information about current context information

>Get-RunInfo

User            : *Domain\Username*
Elevated        : False
Computername    : *computername*
OperatingSystem : Microsoft Windows 10 Entreprise N [64 bits]
BuildNumber     : 1903
BuildVersion    : 10.0.18362
PSVersion       : 5.1.18362.145
Edition         : Desktop
PSHost          : ConsoleHost
WSMan           : 3.0
ExecutionPolicy : Bypass
Culture         : fr-FR

Get-Choice

This function ask for a choice

> Get-Choice -Message "Are you sure?"

Confirm
Are you sure?
[Y] Yes  [N] No  [?] Aide (la valeur par défaut est « Y ») :

Wait-Condition

This function allow to wait until a condition is met

> Wait-Condition -Condition {Get-Process notepad -ErrorAction SilentlyContinue} -Timeout 20 -Verbose

COMMENTAIRES : Wait 20 seconds for the condition to be fulfilled
COMMENTAIRES : Condition not met after [1] seconds...
COMMENTAIRES : Condition not met after [2] seconds...
COMMENTAIRES : Condition not met after [3] seconds...
COMMENTAIRES : Condition not met after [4] seconds...
COMMENTAIRES : Condition not met after [5] seconds...
COMMENTAIRES : Condition not met after [6] seconds...
COMMENTAIRES : Condition met before timeout period.

Watch-Folder

This function watch a folder an return filesystem event in it.

Watch-Folder -Path C:\TEMP

jm.scripttools's People

Contributors

reyozam avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.