Skip to content

Instantly share code, notes, and snippets.

using System;
namespace ConsoleApplication
{
public class Program
{
public static void SimpleMethod()
{
Console.WriteLine("Hello Method World!");
}
function SimpleFunction
{
Out-Host "Hello method host"
}
SimpleFunction
using System;
namespace ConsoleApplication
{
public class Program
{
public static int Increment(int number)
{
return ++number;
}
function Increment
{
Param([int] $number)
$result = $number+1
$result
}
Write-Host "And the answer is" (Increment 41)
function MultipleParameters
{
Param(
[Parameter(Position = 0)][string]$Message,
[Parameter(Position = 1)][string]$SecondMessage,
[Parameter(Position = 2)][bool]$PrintItYellow
)
if($PrintItYellow)
{
Param(
[string]$Message,
[string]$SecondMessage,
[bool]$PrintItYellow
)
if($PrintItYellow)
{
Write-Host "$Message $SecondMessage" -ForegroundColor "Yellow"
}
.\MultipleParameter.ps1 -Message "Hello" -SecondMessage "Dear Reader" -PrintItYellow $true
function DefaultValues
{
Param(
[Parameter(Position = 0)][string]$Message = "Hello from the standard parameters",
[Parameter(Position = 1)][string]$SecondMessage = "",
[Parameter(Position = 2)][bool]$PrintItYellow = $false
)
if($PrintItYellow)
{
"Looks like I'll be the string ending up in a file..." >> "SomeFile.txt"
"What are you complaining about I'll be remembered as the second line..." >> "SomeFile.txt"
$powerShellObject = Invoke-WebRequest "https://mallibone.com"
$Filename = ((Get-Date -format "yyyyMMMdd_HHmm") + "_mallibone_dump.xml")
$powerShellObject.Links | Export-Clixml $Filename