This file contains 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
# Quickly list out all commands in a new PowerShell Module, andcheck that they each have useful help content | |
Get-Command -Module ProfilePal | foreach {get-help $_} |
This file contains 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
# Step 1, filter network adapters to those that are IP & DHCP enabled | |
# - this can only be done with the Win32_NetworkAdapterConfiguration class: | |
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IpEnabled=True AND DhcpEnabled=True' | |
# To get a unique handle to any/all network adapters matching the filtered query, retrieve only their Index propery: | |
(Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IpEnabled=True AND DhcpEnabled=True').Index | |
# Using the Index property, enumerate objects in the Win32_NetworkAdapter class, with the same Index (aka DeviceID) property: | |
# - notice the prior Get-CimInstance query gets wrapped in another $(), to force returning only the resulting value into this Filter statement | |
# - I added | Format-List, because the default Table formatted results truncated the value of the .Name property |
This file contains 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
[mergetool "kdiff3"] | |
cmd = \"c:\program files/TortoiseHg/kdiff3.exe\" '-auto' \"$BASE\" \"$LOCAL\" \"$REMOTE\" '-o' \"$MERGED\" | |
trustExitCode = false |
This file contains 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
http://rosettacode.org/wiki/Repeat_a_string#PowerShell |
This file contains 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
$driveIndex = 1 | |
$env:PSModulePath -split ';' | Sort-Object | foreach { New-PSDrive -Name "PSMods$driveIndex" -PSProvider filesystem -Root $PSItem; $driveIndex++ } | |
Get-PSDrive -PSProvider FileSystem |
This file contains 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
$Private:WinRMListener = & winrm e winrm/config/listener; foreach ($line in $Private:WinRMLTokens = $WinRMListener -split '\n') { $Private:lineTokens = $line -split '=';if ($lineTokens[0] -like '*Source*') { $Private:source = $($lineTokens[1]).trim().replace('"','').replace(']','') }; if ($lineTokens[0] -like '*Transport*') { $Private:Transport = $($lineTokens[1]).trim() }; if ($lineTokens[0] -like '*Port*') { $Private:Port = $($lineTokens[1]).trim() }; if ($lineTokens[0] -like '*Enabled*') { $Private:Enabled = $($lineTokens[1]).trim() }; if ($lineTokens[0] -like '*ListeningOn*') { $Private:ListeningOn = $(($lineTokens[1] -split ',')[0]).trim() } }; $Private:properties = [ordered]@{ 'Source' = $source; 'Transport' = $Transport; 'Port' = $Port; 'Enabled' = $Enabled; 'ListeningIP' = $ListeningOn }; $Private:WinRMListenerInfo = New-Object -TypeName PSObject -Property $properties; $WinRMListenerInfo |
This file contains 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
$MyAcctGroups = Get-WmiObject -Query "ASSOCIATORS OF {Win32_Account.Name='$env:username',Domain='$env:USERDOMAIN'} WHERE ResultRole=GroupComponent REsultClass=Win32_Account" | |
$MyAcctGroups | Get-Member | |
$MyAcctGroups |
This file contains 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
# search string within All Modules | |
# e.g. find '-function' within any file in a module | |
$env:PSModulePath | ForEach-Object { $_ -split ';' | Get-ChildItem -Filter *.ps* -Recurse | Select-String -Pattern 'Write-Log' -SimpleMatch} |
This file contains 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
# Enumerate files (full path) that have a matching string found within | |
# In this example, only PowerShell files (*.ps*1) are being searched for the simple wildcard string 'servicegroup' | |
PS .\> gci -Path .\ -Filter *.ps*1 -Recurse -File | Select-String -SimpleMatch servicegroup | group -Property Path | select -ExpandProperty Name |
This file contains 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
# Starting a new PowerShell (PS) console on a Windows OS instance that has GitHub client for Windows installed ... | |
# Find the local instance of git.exe; it's an 'external' dependency for posh-git | |
Get-ChildItem -Path $env:LocalAppData\GitHub\ -Filter git.exe -Recurse | |
# Should return at least 1 instance of git.exe | |
# Select one and add an alias to it | |
# I choose the one in \bin\ for example: | |
New-Alias -Name git -Value $env:LOCALAPPDATA\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin\git.exe |
OlderNewer