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
$stream = $null | |
try | |
{ | |
$stream = [IO.File]::Open($packagePath, [IO.FileMode]::Create) | |
#$builder.Save($stream); | |
} | |
finally | |
{ | |
if ($stream -ne $null) | |
{ |
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
Use-NuGetPackage ManagedEsent -Verbose #Require PSNuGet<https://github.com/altrive/PSNuGet> | |
$dictionary = New-Object 'Microsoft.Isam.Esent.Collections.Generic.PersistentDictionary[string,string]'("TempData") | |
try | |
{ | |
$key = Read-Host -Prompt "Enter key" | |
if ($dictionary.ContainsKey($key)) | |
{ | |
Write-Host "Key($key) is already exists" | |
} |
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 ( | |
$RequestUrl = "http://127.0.0.1" | |
) | |
function Main | |
{ | |
$ErrorActionPreference = "Stop" | |
Add-Type -AssemblyName System.Net.Http | |
#Reuse connection |
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 Main | |
{ | |
$ErrorActionPreference = "Stop" | |
Add-Type -AssemblyName System.Net.Http | |
Write-Host ("Before: {0} MB" -f ([GC]::GetTotalMemory($true) / 1MB)) | |
foreach ($i in 1..1000) | |
{ | |
Get-ContentFromUrl -url "http://localhost" > $null | |
} |
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
<# | |
.SYNOPSIS | |
Configure Internet Explorer SecurityZone Settings. | |
.DESCRIPTION | |
Note: Configration is not applied immediately, Need to restart related services to apply zone settings. | |
.LINK | |
http://support.microsoft.com/kb/184456/en-us |
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 Main | |
{ | |
#1.No attribute | |
$a = 5; | |
Write-Host ($a) #5 | |
#2.With Add Value attribute | |
[AddValue(5)] | |
$b = 5; | |
Write-Host $b #5+5 =10 |
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
#Requires -RunAsAdministrator | |
function Main | |
{ | |
$ErrorActionPreference = "Stop" | |
$VerbosePreference = "Continue" | |
#Target account to assign previlage | |
$svcAccount = "TestSvc" |
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
Use-NuGetPackage Mono.CSharp -Verbose | |
#Setup Mono C# evaluater | |
$settings = New-Object Mono.CSharp.CompilerSettings | |
$printer = New-Object Mono.CSharp.ConsoleReportPrinter | |
$context = New-Object Mono.CSharp.CompilerContext($settings, $printer); | |
$evaluator = New-Object Mono.CSharp.Evaluator($context); | |
$evaluator.Run("using System; using System.Linq") > $null | |
#Define Func<int,int> return n^2 |
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 Main | |
{ | |
$ErrorActionPreference = "Stop" | |
Invoke-WithProgress -Activity "Test" -Action { | |
foreach ($i in 1..100) | |
{ | |
$progress.UpdateProgress($i) | |
sleep -Milliseconds 10 | |
} |
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
[Linq.Enumerable]::Any((Get-Service), [Func[object, bool]]{ param ($p) $p.Status -eq "Running" }) | |
[Linq.Enumerable]::Where((Get-Service), [Func[object, bool]]{ param ($p) $p.Status -eq "Running" }) |