Format:
Recent snippets matching tags of powershell
task Test -depends Compile {
$origin_directory = pwd
cd $build_directory
$test_assemblies = dir $build_directory -filter *test*.dll | foreach {$_.FullName }
$gsnap = Get-PSSnapin -name Gallio
if($gsnap -eq $null){
Add-PSSnapIn Gallio
}
Run-Gallio $test_assemblies -verbose -ReportTypes Html-Condensed -ReportDirectory $test_report_directory
cd $origin_directory
38 Views
no comments
function Send-Tweet { param ([string]$tweet) $url = "https://twitter.com/statuses/update.xml" $str = "status=" + $tweet Post-Twitter $url $str } function Send-DirectTweet { param ([string]$tweet,[string]$recipient) $url = "https://twitter.com/direct_messages/new.xml"
104 Views
no comments
function Send-Tweet { param ([string]$tweet) $twitUrl = "https://twitter.com/statuses/update.xml" $str = "status=" + $Tweet Post-Twitter $twitUrl $str } function Send-DirectTweet { param ([string]$tweet,[string]$recipient) $twitUrl = "https://twitter.com/direct_messages/new.xml"
78 Views
no comments
function global:out-zip($path){ $files = $input if (-not $path.EndsWith('.zip')) {$path += '.zip'} if (-not (test-path $path)) { set-content $path ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) } $zip=resolve-path($path) $ZipFile = (new-object -com shell.application).NameSpace( "$zip" )
202 Views
1 comments
foreach ($adminGroup in gwmi -computer "." Win32_Group | where {$_.SID -eq "S-1-5-32-544"} | select -Property __PATH) {foreach ($userPart in gwmi Win32_GroupUser | where {$_.GroupComponent -eq $adminGroup.__PATH} | select PartComponent) {gwmi Win32_Account | where {$_.__PATH -eq $userPart.PartComponent} | select @{Name="Account";Expression={$_.Caption}}}}
41 Views
no comments
param ([string] $filename) function splitString([string]$string, [int]$length) { $lines = @(); $stringLength = $string.Length; $position = 0; while ($position -lt $stringLength) {
179 Views
no comments
$assemblyPath = resolve-path(".\Tino.Deployment.dll") [Reflection.Assembly]::LoadFile( $assemblyPath ) | out-null $deployer = new-object Tino.Deployment.CodeCampServerDeployment $environment= new-object Tino.Deployment.Environment "Test" $environment.AddInstance("wwwqa1","web").AddInstance("wwwqa2","web").AddInstance("wwwqa3","web").AddInstance("sqlqa1","db")
255 Views
no comments
public class Deployer { public void Go() { //this is the type of code I would like to see in powershell var deployment = new CodeCampServerDeployment(); Environment qa = new Environment("qa") .AddInstance("fooServer", "web", "db");
190 Views
no comments
$isAdmin = !(($env:SESSIONNAME).Length -gt 0) function Prompt { if ($isAdmin) { $host.ui.RawUI.WindowTitle = '[Admin] ' + $(get-location) "#>" } else
198 Views
no comments
$path = resolve-path . $rand = New-Object system.random $port = $rand.next(2048,10240) $path_to_devserver = "C:\\Program Files (x86)\\Common Files\\microsoft shared\\DevServer\\9.0\\Webdev.WebServer.exe" & $path_to_devserver /port:$port /path:$path (new-object -com shell.application).ShellExecute("http:\\localhost:$port")
172 Views
no comments
properties {
# **************** CONFIGURE ****************
$solution_name = "Framework"
$test_library = "$solution_name.Test.dll"
$libraries_to_merge = "antlr3.runtime.dll", `
"ajaxcontroltoolkit.dll", `
"Castle.DynamicProxy2.dll", `
"Castle.Core.dll", `
185 Views
no comments
# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. # Find the largest palindrome made from the product of two 3-digit numbers. $sw = [System.Diagnostics.Stopwatch]::StartNew() $maxp = 0 for($x = 999; $x -gt 99; $x --) { for($i = $x; $i -gt 99; $i --) { $pp = $x * $i if ($pp -lt $maxp) {
65 Views
no comments
#The prime factors of 13195 are 5, 7, 13 and 29. #What is the largest prime factor of the number 600851475143 ? function getPrimes { #sieve of eratosthenes, http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes param ($target) $nums = @(2..$target) $curPrime = 2 for ($i = 0; [math]::pow($curPrime, 2) -le $target; $i ++) { if ($nums[$i] -ne -1) { $curPrime = $nums[$i]
87 Views
no comments
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. # Find the sum of all the multiples of 3 or 5 below 1000. $target = 999 #first solution (easy) $vals=1..$target $ansA = 0 foreach($v in $vals) { if($v % 3 -eq 0 -or $v % 5 -eq 0) {
63 Views
no comments
param ( [string]$server = ".", [string]$instance = $(throw "a database name is required"), [string]$query ) [System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient") | out-null $connection = new-object system.data.oracleclient.oracleconnection( ` "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$server)(PORT=1521)) ` (CONNECT_DATA=(SERVICE_NAME=$instance)));User Id=USER_ID;Password=PASSWORD;");
387 Views
no comments
param ( [string]$server = ".", [string]$instance = $(throw "a database name is required"), [string]$query ) $connection = new-object system.data.sqlclient.sqlconnection( ` "Data Source=$server;Initial Catalog=$instance;Integrated Security=SSPI;"); $adapter = new-object system.data.sqlclient.sqldataadapter ($query, $connection)
298 Views
2 comments
# # check disk space # Author : Barry 'Ackros' Reilly # Date: August 2009 # Revision : A03 # SystemName,Label,Name,DriveLetter,DriveType,Capacity,Freespace # param ( [string] $Hostname
93 Views
no comments
param ([string]$computerName = (gc env:computername)) function GetExceptionType($type, $logEvent) { if ($type -ne "Error") { $logEvent.ReplacementStrings[17] } else { $rx = [regex]"Exception:.([0-9a-zA-Z].+)" $matches = $rx.match($logEvent.ReplacementStrings[0]) $matches.Groups[1].Value }
176 Views
no comments
function truncate-string([string]$value, [int]$length) { if ($value.Length -gt $length) { $value.Substring(0, $length) } else { $value } }
273 Views
no comments
param ( $fileToImport = $(throw "must have a file to import!") ) $from = "myemail@domain.com" $smtpServer = "smtp.server" $logoName = "d:\path_to_embedded_File\logo.jpg" #Import-Csv $fileToImport | # select to, htmlContent, AttachmentFileName |
119 Views
no comments
function ReadyEnvironment ( [string]$sharedDrive, [string]$userName, [string]$computerName) { set-variable tools "$sharedDrive\shared_tools" -scope 1 set-variable scripts "$sharedDrive\shared_scripts" -scope 1 set-variable rdpDirectory "$sharedDrive\shared_tools\RDP" -scope 1 set-variable desktop "C:\Users\$userName\DESKTOP" -scope 1 Write-Host "Setting environment for $computerName" -foregroundcolor cyan
377 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
