PoshCode Archive  Artifact [49b64dc550]

Artifact 49b64dc550491c32e111c11cfc4ea9a20991e90f35a11bcc326ed96a6ca8e5a9:

  • File Get-StrictMode-psm1.ps1 — part of check-in [25941643fc] at 2018-06-10 13:20:52 on branch trunk — Retrieve the Set-StrictMode session setting. Use as a Module (psm1) and expose any of the user’s settings, but the ‘latest’ parameter cannot be retrieved at present. (user: Archdeacon size: 1964)

# encoding: ascii
# api: powershell
# title: Get-StrictMode.psm1
# description: Retrieve the Set-StrictMode session setting. Use as a Module (psm1) and expose any of the user’s settings, but the ‘latest’ parameter cannot be retrieved at present.
# version: 2.0
# type: function
# author: Archdeacon
# license: CC0
# function: Get-Version
# x-poshcode-id: 3137
# x-archived: 2012-01-14T07:07:16
# x-published: 2012-01-01T17:25:00
#
#
function Get-Version {
<#
.SYNOPSIS
V2.0 Incorporate Version() and ToString() Methods, 1 Jan 2012.
A very simple module to retrieve the Set-StrictMode setting of the user 
session.
.DESCRIPTION
This procedure is necessary as there is, apparently, no equivalent Power-
Shell variable for this and it enables the setting to be returned to its 
original state after possibly being changed within a script.
.EXAMPLE
Get-StrictMode
The various values returned will be Version 1, Version 2, or Off.
.EXAMPLE
$a = (Get-StrictMode).Version()
This will allow the environment to be restored just by entering the commmand
Invoke-Expression "Set-StrictMode $a"
#>
   $version = '0'
   try {
      $version = '2'
      $z = "2 * $nil"       #V2 will catch this one.
      $version = '1'
      $z = 2 * $nil         #V1 will catch this.
      $version = 'Off'
   }
   catch {
   }
   New-Module -ArgumentList $version -AsCustomObject {
      param ($version)
      function Version() {
         if ($version -eq 'Off') {
            $output = '-Off'
         }
         else {
            $output = "-Version $version"
         }
         "$output"                #(Get-StrictMode).Version()
      }
      function ToString() {
         $output = $version
         if ($version -ne 'Off') {
            $output = "Version $version"
         }
         "StrictMode: $output"   #Get-StrictMode output string.
      }
      Export-ModuleMember -function Version,ToString 
   }
}