Skip to content

Instantly share code, notes, and snippets.

View Sambardo's full-sized avatar

Kory Sambardo

View GitHub Profile
Function MyFunction
{
[cmdletbinding(DefaultParameterSetName="ProcessSet")]
param([parameter(Mandatory,ParameterSetName="ServiceSet")]$service,
[parameter(Mandatory,ParameterSetName="ProcessSet")]$Process,
$Test)
switch($PSCmdlet.ParameterSetName)
{
Function MyFunction
{
[cmdletbinding()]
param([parameter(Mandatory,ParameterSetName="ServiceSet")]$service,
[parameter(Mandatory,ParameterSetName="ProcessSet")]$Process,
$Test)
switch($PSCmdlet.ParameterSetName)
{
Function MyFunction
{
[cmdletbinding()]
param([parameter(Mandatory,ParameterSetName="ServiceSet")]$service,
[parameter(Mandatory,ParameterSetName="ProcessSet")]$Process,
$Test)
Write-host "Service: $service" -ForegroundColor Green
Write-host "Process: $process" -ForegroundColor Yellow
Write-host "test: $test" -ForegroundColor Magenta
Function MyFunction
{
[cmdletbinding(SupportsShouldProcess,
ConfirmImpact = "high")]
param($service)
if($PSCmdlet.ShouldProcess($service,"Fetch service"))
{
get-service -name $service
}
Function MyFunction
{
[cmdletbinding(SupportsShouldProcess,
ConfirmImpact = "high")]
param($service)
if($PSCmdlet.ShouldProcess($service,"Fetch service"))
{
get-service -name $service
}
Function MyFunction
{
[cmdletbinding(SupportsShouldProcess)]
param($service)
if($PSCmdlet.ShouldProcess($service,"Fetch service"))
{
get-service -name $service
}
}
write-host "calling normally" -ForegroundColor Yellow
Function MyFunction
{
[cmdletbinding(SupportsShouldProcess)]
param()
Write-host "some host message" -ForegroundColor Green
}
MyFunction -WhatIf
MyFunction -Confirm
Function MyFunction
{
[cmdletbinding()]
param()
Write-error "Some custom error message"
Write-host "some host message" -ForegroundColor Green
get-process FAKE
}
write-host "running normally" -ForegroundColor Yellow
Function MyFunction
{
[cmdletbinding()]
param()
Write-verbose "Some verbose message"
Write-host "some host message" -ForegroundColor Green
}
write-host "running normally" -ForegroundColor Yellow
MyFunction
Function MyFunction
{
[cmdletbinding()]
param()
}