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
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
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
```
Minimum PowerShell version
5.1
Installation Options
Owners
Copyright
(c) 2022 Apteco GmbH. All rights reserved.
Package Details
Author(s)
- florian.von.bracht@apteco.de
Tags
PSEditions
Dependencies
This module has no dependencies.
Release Notes
0.9.0 Initial release of extending functions module through psgallery
FileList
- ExtendFunction.nuspec
- ExtendFunction.psd1
- ExtendFunction.psm1
- publish.ps1
- Public\Get-BaseParameters.ps1
- Public\Skip-UnallowedBaseParameters.ps1
Version History
Version | Downloads | Last updated |
---|---|---|
0.9.0 (current version) | 310 | 11/3/2022 |