This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 7 - From PSObject by iterating properties | |
# and adding key-value pairs | |
$Object = New-Object psobject -Property @{ | |
a = 1 | |
b = 2 | |
} | |
$Hashtable = @{} # emtpy hashtable | |
# access the properties of [PSObject] and iterate them |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 6 - Using Dictionary PowerShell Type Accelarator | |
$Dictionary = [System.Collections.Generic.Dictionary[string,int]]::new() | |
$Dictionary.id = 101 | |
$Dictionary.age = 29 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 5 - Using strongly typed Dictionary | |
$Dictionary = New-Object 'System.Collections.Generic.Dictionary[String,String]' | |
$Dictionary['First'] = 'Prateek' | |
$Dictionary['Last'] = 'Singh' | |
$Dictionary['Age'] = 29 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Hashtable = [System.Collections.Specialized.OrderedDictionary]::new() | |
$Hashtable['First'] = 'Prateek' | |
$Hashtable['Last'] = 'Singh' | |
$Hashtable['Age'] = 29 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 3 - Using HashTable PowerShell type accelerator | |
$Hashtable = [hashtable]::new() | |
$Hashtable['First'] = 'Prateek' | |
$Hashtable['Last'] = 'Singh' | |
$Hashtable['Age'] = 29 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 2 - Using .Net class for Hashtable | |
$Hashtable = New-Object System.Collections.Hashtable | |
$Hashtable['First'] = 'Prateek' | |
$Hashtable['Last'] = 'Singh' | |
$Hashtable['Age'] = 29 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 1 - Using @{ } | |
$Hashtable = @{ | |
First = 'Prateek' | |
Last = 'Singh' | |
Age = 29 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 1 - Using @{ } | |
$Hashtable = @{ | |
First = 'Prateek' | |
Last = 'Singh' | |
Age = 29 | |
} | |
# Method 2 - Using .Net class for Hashtable | |
$Hashtable = New-Object System.Collections.Hashtable | |
$Hashtable['First'] = 'Prateek' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function global:prompt { | |
# Multiple Write-Host commands with color | |
$path = (Get-Culture).TextInfo.ToTitleCase($pwd) | |
Write-Host $path -foregroundcolor Cyan | |
Write-Host '>' -ForegroundColor Blue -NoNewline | |
return " " | |
} |