Skip to content

Commit da39b97

Browse files
committed
Snippets
1 parent 5e8cd3b commit da39b97

31 files changed

+200
-227
lines changed
File renamed without changes.

Snippets/.NET Type Examples.ps1

Lines changed: 0 additions & 9 deletions
This file was deleted.

Snippets/Average Time to Run a Command.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ function Get-AverageExecutionTime {
1717
[CmdletBinding()]
1818
param (
1919
[Parameter(
20-
Mandatory=$true,
21-
HelpMessage="Specify a scriptblock to measure the execution time of."
20+
Mandatory = $true,
21+
HelpMessage = 'Specify a scriptblock to measure the execution time of.'
2222
)]
23-
[scriptblock]$Scriptblock,
23+
[scriptblock]$Scriptblock,
2424

2525
[Parameter(
26-
Mandatory=$false,
27-
HelpMessage="Specify the number of times to run the scriptblock. (Default 50)"
26+
Mandatory = $false,
27+
HelpMessage = 'Specify the number of times to run the scriptblock. (Default 50)'
2828
)]
29-
[int]$Count = 50
29+
[int]$Count = 50
3030
)
3131

3232
begin {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Check if a string exists as a key in a hash table
2-
$StringToCheck = "SomeString"
2+
$StringToCheck = 'SomeString'
33
if ($null -eq $HashTable[$StringToCheck]) {
44
Write-Output "The key [$StringToCheck] does not exist in the hash table"
5-
}
6-
else {
5+
} else {
76
Write-Output "The key [$StringToCheck] exists in the hash table"
87
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function Diffy {
22
code --diff $args[0] $args[1]
3-
}
3+
}

Snippets/Custom Object Examples.ps1

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$BuildVersion = "23.03.15.2119"
1+
$BuildVersion = '23.03.15.2119'
22

33
$scriptName = $script:MyInvocation.MyCommand.Name
44
$scriptPath = [IO.Path]::GetDirectoryName($script:MyInvocation.MyCommand.Path)
@@ -7,7 +7,7 @@ $scriptFullName = (Join-Path $scriptPath $scriptName)
77
$result = [PSCustomObject]@{
88
ScriptName = $scriptName
99
CurrentVersion = $BuildVersion
10-
LatestVersion = ""
10+
LatestVersion = ''
1111
UpdateFound = $false
1212
Error = $null
1313
}
@@ -22,24 +22,24 @@ function CreateCustomCSV {
2222

2323
$ItemType = $data.ItemClass
2424

25-
if ($data.ItemClass.StartsWith("IPM.Note")) {
26-
$ItemType = "E-Mail"
27-
} elseif ($data.ItemClass.StartsWith("IPM.Appointment")) {
28-
$ItemType = "Calendar"
29-
} elseif ($data.ItemClass.StartsWith("IPM.Task")) {
30-
$ItemType = "Task"
25+
if ($data.ItemClass.StartsWith('IPM.Note')) {
26+
$ItemType = 'E-Mail'
27+
} elseif ($data.ItemClass.StartsWith('IPM.Appointment')) {
28+
$ItemType = 'Calendar'
29+
} elseif ($data.ItemClass.StartsWith('IPM.Task')) {
30+
$ItemType = 'Task'
3131
}
3232

3333
$row = [PSCustomObject]@{
34-
"Mailbox" = $mailbox
35-
"Id" = $data.Id
36-
"ItemType" = $ItemType
37-
"Sender" = ($data.From | Select-Object -ExpandProperty Address) -join ","
38-
"Recipient" = ($data.ToRecipients | Select-Object -ExpandProperty Address) -join ","
39-
"Subject" = $data.Subject
40-
"DateReceived" = $data.DateTimeReceived
41-
"PidLidReminderFileParameter" = $data.ExtendedProperties[0].Value
42-
"Cleanup" = "N"
34+
'Mailbox' = $mailbox
35+
'Id' = $data.Id
36+
'ItemType' = $ItemType
37+
'Sender' = ($data.From | Select-Object -ExpandProperty Address) -join ','
38+
'Recipient' = ($data.ToRecipients | Select-Object -ExpandProperty Address) -join ','
39+
'Subject' = $data.Subject
40+
'DateReceived' = $data.DateTimeReceived
41+
'PidLidReminderFileParameter' = $data.ExtendedProperties[0].Value
42+
'Cleanup' = 'N'
4343
}
4444

4545
$row | Export-Csv -Path $CsvPath -NoTypeInformation -Append -Encoding utf8 -Force
@@ -77,4 +77,4 @@ function Find-ESC8 {
7777
[PSCustomObject] $Issue
7878
}
7979
}
80-
}
80+
}

Snippets/Dynamic Autocomplete Test.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
function Connect-AzureTestCompatible {
33
[CmdletBinding()]
44
Param(
5-
[Parameter(Mandatory=$false)]
5+
[Parameter(Mandatory = $false)]
66
[ArgumentCompleter( {
7-
param ( $CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters )
8-
$Global:EnvironmentNames = (Get-MgEnvironment).Name; $Global:EnvironmentNames
9-
} )]
7+
param ( $CommandName, $ParameterName, $WordToComplete, $CommandAst, $FakeBoundParameters )
8+
$Global:EnvironmentNames = (Get-MgEnvironment).Name; $Global:EnvironmentNames
9+
} )]
1010
[ValidateScript({
11-
if ($_ -in $Global:EnvironmentNames) {
12-
$true
13-
} else {
14-
throw "`n$_ is not a valid environment name. Please use one of the following: $($Global:EnvironmentNames -join ', ')"
15-
}
16-
})]
11+
if ($_ -in $Global:EnvironmentNames) {
12+
$true
13+
} else {
14+
throw "`n$_ is not a valid environment name. Please use one of the following: $($Global:EnvironmentNames -join ', ')"
15+
}
16+
})]
1717
[string]$Environment
1818
)
1919
Connect-MgGraph -Environment $Environment
@@ -32,7 +32,7 @@ Class EnvironmentName : System.Management.Automation.IValidateSetValuesGenerator
3232
function Connect-GraphTest {
3333
[CmdletBinding()]
3434
param(
35-
[Parameter(Mandatory=$false)]
35+
[Parameter(Mandatory = $false)]
3636
[ValidateSet([EnvironmentName])]
3737
[string]$Environment
3838
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# .NET Type Examples:
2+
[System.IO.Path]::GetTempPath()
3+
[System.Globalization.RegionInfo]::CurrentRegion
4+
[IO.File]::ReadAllText($FilePath)
5+
[System.IO.Path]::Combine($Path1, $Path2)
6+
7+
# Using Is Null or Empty
8+
if ([string]::IsNullOrEmpty($customNames)) {
9+
# Do something
10+
}
11+
12+
# Load the .NET assembly to make it available to the whole script or session
13+
Add-Type -AssemblyName 'System.DirectoryServices'
14+
Add-Type -AssemblyName 'System.Net.NetworkInformation'
15+
# Works when offline, returns the DNS domain name, not the NetBIOS domain name:
16+
( [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties() ).DomainName
17+
# Requires domain connectivity, returns the DNS domain name, not the NetBIOS domain name:
18+
[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name
19+
# Find a global catalog server:
20+
[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Forest.FindGlobalCatalog().Name
21+
# Find a domain controller:
22+
[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().FindDomainController().Name

Snippets/Expand-ShortUrl.ps1

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)