CodePaste Logo
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
<#
.COMPONENT
    NUPosh
.SYNOPSIS
    Test if an Assembly (.dll) is already loaded. 
.DESCRIPTION
    Test if an Assembly of the same name is already loaded in the current runspace. 
    Using the -PasThru parameter will return the AssemblyInfo object along with the boolean. 
.PARAMETER  Name
    The file name of the Assembly.   
by qawarrior   Thursday @ 7:42am
30 Views
no comments
 
$isAdmin = !(($env:SESSIONNAME).Length -gt 0)
 
function Prompt
{
  $pwd = $(get-location)
  if ($isAdmin)
  {
    $host.ui.RawUI.WindowTitle = "Administrator: $pwd"
    "PS $pwd># "    
  }
by Matthew Flaschen   October 18, 2011 @ 6:09pm
78 Views
no comments
 
C#
Sol Reqs:
.NET 3.5
x64
Add Ref: Microsoft.SharePoint assembly 
 
// Applying a template to a new site
Site Actions –> New Site. You'll find your Site Template in the list of Installed Items, in the All Categories or Blank & Custom filters.
 
//  how to upgrade the content database - after applying SP1
C:\Program Files\Common Files\Microsoft Shared\Web ServerExtensions\14\bin\psconfig.exe –cmd upgrade
by Jose David Parra   August 11, 2011 @ 7:48pm
307 Views
no comments
 
Get-Process | Where-Object {$_.ProcessName -like "w*"}
 
Table 1-4. Commonly Used Windows PowerShell Comparison Operators
 
Operator    Purpose
-lt    Less than
-le    Less than or equal to
-gt    Greater than
-ge    Greater than or equal to
-eq    Equal to
by Jose David Parra   August 10, 2011 @ 3:42pm
120 Views
no comments
 
#http://www.nivot.org/2009/03/26/PowerShell20CTP3ModulesInPracticeNETInterfaces.aspx
 
function Get-Interface {
 
#.Synopsis
#   Allows PowerShell to call specific interface implementations on any .NET object. 
#.Description
#   Allows PowerShell to call specific interface implementations on any .NET object. 
#
#   As of v2.0, PowerShell cannot cast .NET instances to a particular interface. This makes it
350 Views
no comments
 
#requires get-interface from http://www.nivot.org/2009/03/26/PowerShell20CTP3ModulesInPracticeNETInterfaces.aspx
# this needs to be program files x86 if in 64 bit context
$runtimeDir="$env:ProgramFiles\Inishtech SLP Code Protector"
add-type -path "$runtimeDir\Microsoft.Licensing.Runtime2.0.DLL"
$shortCode = "abc12"
$r = new-object Microsoft.Licensing.SLMRuntime $shortCode
$a = get-interface $r.Activation ([Microsoft.Licensing.ISLMActivation])
$ac = get-interface $a.CreateActivationClient("Product","1.0") ([Microsoft.Licensing.IActivationClient])
$activationKey="29KV3-E4T9M-WDTTD-KNVZB-YUVZZ"
$ac.Activate( $activationKey, "") 
by InishTech   February 17, 2011 @ 4:24pm
187 Views
no comments
 
 
 
$dbDir = "C:\Dev\MyProject\branches\1.0.0\src\Database\"
$viewsDir = [IO.Path]::Combine($dbDir, "Views")
$functionsDir = [IO.Path]::Combine($dbDir, "Functions")
$sprocsDir = [IO.Path]::Combine($dbDir, "Stored Procedures")
$dbServer = "(local)\SQL2k8"
 
#Write-Host $dbDir
#Write-Host $viewsDir
by Jon Sagara   December 27, 2010 @ 5:43pm
181 Views
no comments
 
$newVirtualDirectory = $args[0]
$physicalPath = $args[1]
 
# gets the IIS root object
$iis = [ADSI]"IIS://localhost/w3svc/1/root"
 
$vdir = $iis.psbase.children | where {$_.AppRoot -eq ('/LM/W3SVC/1/Root/' + $newVirtualDirectory)}
 
# Check to see if the virtual directory exists
if (!$vdir) {
by Robert.Eberhart   December 20, 2010 @ 6:52am
306 Views
no comments
 
# -------------------------------------------------------------------------------------------------
# Pinger.ps1
#
# 2011-05-25: moved to gist.github.com
# https://gist.github.com/992625
# -------------------------------------------------------------------------------------------------
by Jon Sagara   December 13, 2010 @ 2:53pm
732 Views
no comments
 
# -------------------------------------------------------------------------------------------------
# InstallUtilPs.ps1
#
# Wrapper around InstallUtil.exe.
# -------------------------------------------------------------------------------------------------
 
# Script params
param([switch]$u) # uninstall
 
$dotNetRuntimeDir = [System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
by Jon Sagara   December 13, 2010 @ 2:50pm
334 Views
no comments
 
Get-ChildItem *.js -Recurse -Path "d:\Projects\trunk\src\" | ForEach-Object {
$content = $_ | Get-Content
Set-Content -PassThru $_.Fullname $content -Encoding UTF8 -Force}
by ZStyle   October 27, 2010 @ 12:36am
177 Views
no comments
 
Write-Host $("{0},{1}" -f "Hello", "World") -fore Red
by David R. Longnecker   May 11, 2010 @ 2:05pm
397 Views
no 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
299 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
748 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
615 Views
1 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
647 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
769 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
250 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
1634 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
1602 Views
2 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