New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
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        
by RhysC   February 15, 2010 @ 11:28pm
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"
January 18, 2010 @ 6:19pm
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"
January 18, 2010 @ 5:49pm
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" ) 
by Eric Hexter   January 17, 2010 @ 6:34pm
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}}}}
by kopelli   November 11, 2009 @ 10:39pm
41 Views
no comments
 
param ([string] $filename)
 
function splitString([string]$string, [int]$length)
{
    $lines = @();
    $stringLength = $string.Length;
    $position = 0;
 
    while ($position -lt $stringLength)
    {
by David R. Longnecker   October 13, 2009 @ 11:00am
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")
 
by Eric Hexter   October 11, 2009 @ 8:35am
255 Views
no comments
 
C#
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");
by Eric Hexter   October 10, 2009 @ 2:15pm
190 Views
no comments
 
$isAdmin = !(($env:SESSIONNAME).Length -gt 0)
 
function Prompt
{
  if ($isAdmin)
  {
    $host.ui.RawUI.WindowTitle = '[Admin] ' + $(get-location)
    "#>"
  }
  else
by Andy Sherwood   September 10, 2009 @ 3:11pm
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")
by David R. Longnecker   September 09, 2009 @ 9:51am
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", `
by David R. Longnecker   September 08, 2009 @ 11:12am
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) {
September 06, 2009 @ 12:03am
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]
September 05, 2009 @ 1:10am
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) {
by Please enter a name...   September 04, 2009 @ 7:02pm
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;");
by David R. Longnecker   September 01, 2009 @ 5:51am
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)
by David R. Longnecker   August 31, 2009 @ 12:07pm
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
by Barry Reilly   August 26, 2009 @ 7:02am
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
 }
by David R. Longnecker   August 25, 2009 @ 12:53pm
176 Views
no comments
 
function truncate-string([string]$value, [int]$length)
{
    if ($value.Length -gt $length) { $value.Substring(0, $length) }
    else { $value }
}
by David R. Longnecker   August 25, 2009 @ 7:34am
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 | 
by David R. Longnecker   August 21, 2009 @ 10:00pm
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
by David R. Longnecker   August 21, 2009 @ 6:39pm
377 Views
no comments
 
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate