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.
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># " }
78 Views
no comments
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
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
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, "")
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
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) {
306 Views
no comments
# ------------------------------------------------------------------------------------------------- # Pinger.ps1 # # 2011-05-25: moved to gist.github.com # https://gist.github.com/992625 # -------------------------------------------------------------------------------------------------
732 Views
no comments
# ------------------------------------------------------------------------------------------------- # InstallUtilPs.ps1 # # Wrapper around InstallUtil.exe. # ------------------------------------------------------------------------------------------------- # Script params param([switch]$u) # uninstall $dotNetRuntimeDir = [System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
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}
177 Views
no comments
Write-Host $("{0},{1}" -f "Hello", "World") -fore Red
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}}}}
299 Views
no comments
param ([string] $filename) function splitString([string]$string, [int]$length) { $lines = @(); $stringLength = $string.Length; $position = 0; while ($position -lt $stringLength) {
748 Views
no comments
$isAdmin = !(($env:SESSIONNAME).Length -gt 0) function Prompt { if ($isAdmin) { $host.ui.RawUI.WindowTitle = '[Admin] ' + $(get-location) "#>" } else
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")
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", `
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) {
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;");
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)
1602 Views
2 comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
