Skip to content

Instantly share code, notes, and snippets.

$stream = $null
try
{
$stream = [IO.File]::Open($packagePath, [IO.FileMode]::Create)
#$builder.Save($stream);
}
finally
{
if ($stream -ne $null)
{
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"
}
param (
$RequestUrl = "http://127.0.0.1"
)
function Main
{
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName System.Net.Http
#Reuse connection
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
}
@altrive
altrive / Add-InternetExploreZoneSetting.ps1
Created March 3, 2014 06:35
Configure Internet Explorer security zone settings.
<#
.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
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
@altrive
altrive / SetAccountPrevilage.ps1
Created February 22, 2014 09:55
Sample code to set LSA account previlage via P/Invoke(LsaAddAccountRights).
#Requires -RunAsAdministrator
function Main
{
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
#Target account to assign previlage
$svcAccount = "TestSvc"
@altrive
altrive / Mono.CSharp.ps1
Last active August 29, 2015 13:56
Call C# code snipped from PowerShell using Mono.CSharp/Roslyn
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
@altrive
altrive / Invoke-WithProgress.ps1
Last active August 29, 2015 13:56
Write-Progress wrapper sample code
function Main
{
$ErrorActionPreference = "Stop"
Invoke-WithProgress -Activity "Test" -Action {
foreach ($i in 1..100)
{
$progress.UpdateProgress($i)
sleep -Milliseconds 10
}
[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" })