Block
Block functions are used to take the place of different stops that I place in my scripts

Example

For example, I have a function that needs the following requirements
  • Runs in Full OS, not WinPE
  • Requires Admin Rights
  • Requires Curl.exe
In my code, I' would do something like this
1
#=======================================================================
2
# Require WinOS
3
#=======================================================================
4
if ((Get-OSDGather -Property IsWinPE)) {
5
Write-Warning "$($MyInvocation.MyCommand) cannot be run from WinPE"
6
Break
7
}
8
#=======================================================================
9
# Require Admin Rights
10
#=======================================================================
11
if ((Get-OSDGather -Property IsAdmin) -eq $false) {
12
Write-Warning "$($MyInvocation.MyCommand) requires Admin Rights ELEVATED"
13
Break
14
}
15
#=======================================================================
16
# Require cURL
17
#=======================================================================
18
if (-NOT (Test-Path "$env:SystemRoot\System32\curl.exe")) {
19
Write-Warning "$($MyInvocation.MyCommand) could not find $env:SystemRoot\System32\curl.exe"
20
Write-Warning "Get a newer Windows version!"
21
Break
22
}
23
#=======================================================================
Copied!
By taking these Blocks into separate functions, I can easily add this to my PowerShell script and greatly simplify things as well as ensuring consistency
1
Import-Module OSD
2
Block-WinPE
3
Block-StandardUser
4
Block-NoCurl
Copied!

Real World Example

In the real world, I have a function that has these blocks in place
And when running the function in PowerShell as a Standard User, I receive the following:

The Code

This is what the code of a Block will do. By default, a Warning with a Timestamp and calling Function will be displayed, followed by a Break. These can be adjusted with two Parameters

-Warn

Provides a Warning without a Break

-Pause

Adds a Press Any Key to continue
Last modified 1yr ago