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
function Parse-SimpleFilter { | |
param([string]$Filter) | |
$err = @() # TODO inspect parsing errors | |
$Tokens = [System.Management.Automation.PSParser]::Tokenize($Filter,[ref]$err) | |
$Elements = foreach($t in $Tokens){ | |
switch($t.Type){ | |
([System.Management.Automation.PSTokenType]::Command) { | |
'$_.{0}' -f $t.Content |
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
function Measure-Lines { | |
param($Path = 'C:\log.txt') | |
$FileStream = New-Object IO.FileStream ($Path,[System.IO.FileMode]::Open,[System.IO.FileAccess]::Read,[System.IO.FileShare]::ReadWrite) | |
$StreamReader = New-Object System.IO.StreamReader $FileStream | |
$TotalLines = 0 | |
while($StreamReader.ReadLine() -ne $null){ | |
$TotalLines++ | |
} | |
$TotalLines |
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
# Most straighforward way I can think of | |
# 2 pairs of curly braces and a single semicolon for the calculated OSVERSION property | |
Import-Csv .\input.csv |Select-Object -Property MACHINENAME,@{Label='OSVERSION';Expression={(Get-WmiObject Win32_OperatingSystem -ComputerName $_.MACHINENAME).Caption}} | Export-Csv .\output.csv -NoTypeInformation |
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
#region new() | |
# new() works not only on PS Classes, but wraps existing .NET ctors as well: | |
[System.Net.WebProxy]::new("proxyserver.contoso.com",3128) | |
#endregion | |
#region Add-Type | |
#region Access modifiers |
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
param([string]$VMNameStr) | |
# Trim whitepsace on input string, | |
# then split at commas (surrounded by 0 or more whitespace chars on each side) | |
$VMNameStr.Trim() -split "\s*,\s*" |
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
gci Test*|select @{Name="Path";Expression={[regex]::Replace($_.FullName,"\[|\]|\*|\?",{'`{0}'-f$args[0]})}}|gci -Recurse |
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
if((New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 (,[byte[]]@(45,45,45,45,45,66,69,71,73,78,32,67,69,82,84,73,70,73,67,65,84,69,45,45,45,45,45,10,77,73,73,67,56,122,67,67,65,100,43,103,65,119,73,66,65,103,73,81,97,56,86,55,108,82,105,84,113,112,100,76,89,107,114,65,105,80,119,55,116,106,65,74,66,103,85,114,68,103,77,67,72,81,85,65,77,66,81,120,69,106,65,81,10,66,103,78,86,66,65,77,84,67,87,86,69,90,87,120,115,85,109,57,118,100,68,65,101,70,119,48,120,78,84,65,48,77,68,99,120,77,68,73,122,77,106,100,97,70,119,48,122,79,84,69,121,77,122,69,121,77,122,85,53,78,84,108,97,10,77,66,81,120,69,106,65,81,66,103,78,86,66,65,77,84,67,87,86,69,90,87,120,115,85,109,57,118,100,68,67,67,65,83,73,119,68,81,89,74,75,111,90,73,104,118,99,78,65,81,69,66,66,81,65,68,103,103,69,80,65,68,67,67,10,65,81,111,67,103,103,69,66,65,76,51,82,74,103,49,117,122,86,117,69,88,48,72,119,52,88,87,71,122,115,54,111,73,57,87,43,111,55,72,90,100,86,100,66,77,77,86,98,52,71,122,98,52,117,90,106,67,84,78,106,98,80,120,52 |
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
function Get-AST | |
{ | |
param( | |
[Parameter(Mandatory,ValueFromPipeline)] | |
[psobject[]]$InputObject | |
) | |
process{ | |
foreach($Script in $InputObject){ | |
$Tokens = $Errors = @() |
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
param($u)(&{if($c-is[System.Net.WebClient]){$c}else{($global:c=New-Object System.Net.WebClient)}}).DownloadString($u) |
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
$list = @" | |
1 Partridge in a pear tree | |
2 Turtle Doves | |
3 French Hens | |
4 Calling Birds | |
5 Golden Rings | |
6 Geese a laying | |
7 Swans a swimming | |
8 Maids a milking | |
9 Ladies dancing |