ExtendFunction

0.9.0

Apteco PS Modules - PowerShell functions extension

This function helps to gather all parameters that a function/cmdlet has
except the common parameters like -verbose etc.

This can be used to extend existing functions/cmdlets with more scripting
and possibly additional parameters.

So in this example you see how it works

```PowerShell

# These functions
Apteco PS Modules - PowerShell functions extension

This function helps to gather all parameters that a function/cmdlet has
except the common parameters like -verbose etc.

This can be used to extend existing functions/cmdlets with more scripting
and possibly additional parameters.

So in this example you see how it works

```PowerShell

# These functions inherit the parameters of the original functions/cmdlets
# And as an example adds an additional parameter
# There are two functions for the different PowerShell Editions

function Invoke-DesktopWebRequest {

   [CmdletBinding()]
   param (
       [Parameter(Mandatory=$true)][string]$AdditionalString
   )
   DynamicParam { Get-BaseParameters "Invoke-WebRequest" }

   Process {
       Write-Host "Using `$PSEdition: Desktop"
       Write-Host $AdditionalString
       $updatedParameters = Skip-UnallowedBaseParameters -Base "Invoke-WebRequest" -Parameters $PSBoundParameters
       Invoke-WebRequest @updatedParameters

   }

}

function Invoke-CoreWebRequest {
   
   [CmdletBinding()]
   param (
       [Parameter(Mandatory=$true)][string]$AdditionalString
   )
   DynamicParam { Get-BaseParameters "Invoke-WebRequest" }

   Process {
       Write-Host "Using `$PSEdition: Core"
       Write-Host $AdditionalString
       $updatedParameters = Skip-UnallowedBaseParameters -Base "Invoke-WebRequest" -Parameters $PSBoundParameters
       Invoke-WebRequest @updatedParameters
   }

}

```

And this can be used like

```PowerShell

#-----------------------------------------------
# CREATE AN ALIAS DEPENDING ON $PSEdition
#-----------------------------------------------

# In this example differentiates between Core and Desktop, but creates one alias for different $PSEdition
# Just type $PSEdition if you want to know which edition you are using

Switch ( $PSEdition ) {

   "Desktop" {
       Set-Alias -Name Invoke-WebRequestExtended -Value Invoke-DesktopWebRequest -Force
   }

   "Core" {
       Set-Alias -Name Invoke-WebRequestExtended -Value Invoke-CoreWebRequest -Force
   }

}


#-----------------------------------------------
# EXAMPLE TO LOAD DATA WITH THE NEW ALIAS
#-----------------------------------------------

$myParams = [Hashtable]@{
   Uri = "https://api.chucknorris.io/jokes/random"
   Method = "Get"
   Verbose = $true
   AdditionalString = "Hello World"
}
$wr = Invoke-WebRequestExtended @myParams
( $wr.content | ConvertFrom-Json ).Value


```

Show more

Minimum PowerShell version

5.1

Installation Options

Copy and Paste the following command to install this package using PowerShellGet More Info

Install-Module -Name ExtendFunction

Copy and Paste the following command to install this package using Microsoft.PowerShell.PSResourceGet More Info

Install-PSResource -Name ExtendFunction

You can deploy this package directly to Azure Automation. Note that deploying packages with dependencies will deploy all the dependencies to Azure Automation. Learn More

Manually download the .nupkg file to your system's default download location. Note that the file won't be unpacked, and won't include any dependencies. Learn More

Owners

Copyright

(c) 2022 Apteco GmbH. All rights reserved.

Package Details

Author(s)

  • florian.von.bracht@apteco.de

Tags

Windows Apteco

PSEditions

Desktop Core

Dependencies

This module has no dependencies.

Release Notes


0.9.0 Initial release of extending functions module through psgallery

FileList

Version History

Version Downloads Last updated
0.9.0 (current version) 191 11/3/2022