LogoLogo
OSDeploy.comTwitterGitHubPowerShell Gallery
  • OSD PowerShell Module
  • Functions
  • Docs
    • OSDCloud
    • OSDPad
    • OSDHelp
      • Autopilot
    • Guides
      • UEFI System Firmware Update
      • In Your Code
      • New-OSDBoot.usb
      • Partitions
        • New-OSDDisk (Information)
        • New-OSDDiskWinPE (GPT)
        • New-OSDDiskWinPE (2 Disks)
        • AutoUnattend.xml
    • OSDWindowsImage
    • Windows Setup Environment
      • Execution Policy
      • WinSE Settings
      • Import Modules
      • Automation
    • Release Notes
    • Trash
      • Adk
        • Edit-ADKwinpe.wim
        • Get-ADKpaths
        • New-ADK.iso
        • New-ADKcopype
      • Appx
      • Block
      • CloudDriver
      • Dell
        • Get-DellCatalogPC
        • Get-MyDellBIOS
        • Update-MyDellBios
      • Disk
        • Backup-Disk.ffu
        • Clear-LocalDisk
        • Clear-USBDisk
        • Get-LocalDisk
        • Get-OSDDisk
        • Get-USBDisk
        • New-OSDisk
          • Old Version
            • Sandbox
            • Partition Layout
            • Partition Sizes
            • Volume Labels
            • AutoUnattend.xml
        • Get-USBVolume
      • Dism
        • Get-MyWindowsCapability
        • Get-MyWindowsPackage
        • Set-WimExecutionPolicy
        • Set-WindowsImageExecutionPolicy
      • Display
        • Get-VidConRes
      • Driver
        • Get-OSDDriverWmiQ
        • Get-OSDDriver
      • General
        • Get-OSD
        • Get-OSDClass
        • Get-OSDGather
        • Get-OSDPower
        • Get-RegCurrentVersion
        • Get-SessionsXml
        • Save-OSDDownload
      • MyBitLocker
        • Get-MyBitLockerKeyProtectors
        • Backup-MyBitLocker
        • Save-MyBitLockerExternalKey
        • Save-MyBitLockerKeyPackage
        • Save-MyBitLockerRecoveryPassword
        • Unlock-MyBitLockerExternalKey
      • OOBE
      • PSModule
        • Copy-PSModuleToFolder
        • Copy-PSModuleToWim
        • Copy-PSModuleToWindowsImage
      • WebConnection
      • WebPSScript
      • WinPEWim
      • WinPE
        • Enable-PEWimPSGallery
        • Get-OSDWinPE
Powered by GitBook
On this page
  • Example
  • Real World Example
  • The Code

Was this helpful?

  1. Docs
  2. Trash

Block

PreviousAppxNextCloudDriver

Last updated 4 years ago

Was this helpful?

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

    #=======================================================================
    #	Require WinOS
    #=======================================================================
    if ((Get-OSDGather -Property IsWinPE)) {
        Write-Warning "$($MyInvocation.MyCommand) cannot be run from WinPE"
        Break
    }
    #=======================================================================
    #   Require Admin Rights
    #=======================================================================
    if ((Get-OSDGather -Property IsAdmin) -eq $false) {
        Write-Warning "$($MyInvocation.MyCommand) requires Admin Rights ELEVATED"
        Break
    }
    #=======================================================================
    #   Require cURL
    #=======================================================================
    if (-NOT (Test-Path "$env:SystemRoot\System32\curl.exe")) {
        Write-Warning "$($MyInvocation.MyCommand) could not find $env:SystemRoot\System32\curl.exe"
        Write-Warning "Get a newer Windows version!"
        Break
    }
    #=======================================================================

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

Import-Module OSD
Block-WinPE
Block-StandardUser
Block-NoCurl

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