full_path
stringlengths
31
232
filename
stringlengths
4
167
content
stringlengths
0
48.3M
PowerShellCorpus/PoshCode/SVMotion-VM_1.ps1
SVMotion-VM_1.ps1
# author: Hal Rottenberg # Website/OpenID: http://halr9000.com # purpose: does "real" SVMotion of a VM # usage: get-vm | SVMotion-VM -destination (get-datastore foo) function SVMotion-VM { param( [VMware.VimAutomation.Client20.DatastoreImpl] $destination ) Begin { $datastoreView = get-view $destina...
PowerShellCorpus/PoshCode/Compare-Agents_1.ps1
Compare-Agents_1.ps1
#This scripts compares the agents that are installed in two zones and #gives the agents that are not common. #Usage: #Compare-Agents.ps1 -server1 RMSServer1.contoso.com -server2 RMSServer2.contoso.com -output c:\\Temp.txt #RMSServer1 is the one whose agents are to be moved. param([string] $Server1,$Server2,$outp...
PowerShellCorpus/PoshCode/ISE-Snippets.ps1
ISE-Snippets.ps1
#requires -version 2.0 ## ISE-Snippets module v 1.0 ## DEVELOPED FOR CTP3 ## See comments for each function for changes ... ############################################################################################################## ## As a shortcut for every snippet would be to much, I created Add-Snippet whic...
PowerShellCorpus/PoshCode/Set-WebConfig.ps1
Set-WebConfig.ps1
function Set-WebConfigSqlConnectionString { param( [switch]$help, [string]$configfile = $(read-host "Please enter a web.config file to read"), [string]$connectionString = $(read-host "Please enter a connection string"), [switch]$backup = $TRUE ) $usage = "`$conString = `"Data S...
PowerShellCorpus/PoshCode/Save-Credentials_1.ps1
Save-Credentials_1.ps1
<# .SYNOPSIS The script saves a username and password, encrypted with a custom key to to a file. .DESCRIPTION The script saves a username and password, encrypted with a custom key to to a file. The key is coded into the script but should be changed before use. The key allows the password to be decrypted ...
PowerShellCorpus/PoshCode/Import-NmapXML.ps1
Import-NmapXML.ps1
#Requires -Version 2.0 function Import-NmapXML { #################################################################################### #.Synopsis # Parse XML output files of the nmap port scanner (www.nmap.org). # #.Description # Parse XML output files of the nmap port scanner (www.nmap.org) and ...
PowerShellCorpus/PoshCode/LibrarySqlBackup_1.ps1
LibrarySqlBackup_1.ps1
# --------------------------------------------------------------------------- ### From the Apress book "Pro Windows PowerShell" p. 164 I found the following trap handler that will get to the InnerException.Message # --------------------------------------------------------------------------- trap { $exceptionty...
PowerShellCorpus/PoshCode/Get-WebFile 4.1.ps1
Get-WebFile 4.1.ps1
function ConvertTo-Dictionary { param( [Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="Hashtable")] [Hashtable[]]$Hashtable, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,ParameterSetName="WebHeaders")] [System.Collections.Specialized.Na...
PowerShellCorpus/PoshCode/Get-LocalGroups.ps1
Get-LocalGroups.ps1
function Add-NoteProperty { <# .Synopsis Adds a NoteProperty member to an object. .Description This function makes adding a property a lot easier than Add-Member, assuming you want to add a NoteProperty, which I find is true about 90% of the time. .Parameter object The object to add the property to. ...
PowerShellCorpus/PoshCode/Binary Clock.ps1
Binary Clock.ps1
<# .SYNOPSIS This is a binary clock that lists the time in hours, minutes and seconds .DESCRIPTION This is a binary clock that lists the time in hours, minutes and seconds. Also available is the ability to display the time in a "human readable" format, display the date and display a helper displ...
PowerShellCorpus/PoshCode/Split-String_1.ps1
Split-String_1.ps1
function Split-String { #.Synopsis # Split a string and execute a scriptblock to give access to the pieces #.Description # Splits a string (by default, on whitespace), and assigns it to $0, and the first 9 words to $1 through $9 ... and then calls the specified scriptblock #.Example # echo "this is one test ff...
PowerShellCorpus/PoshCode/Highlight syntax.ps1
Highlight syntax.ps1
#code which need highlight $code = @' #just example Get-Process | % { try { "{0, 7} {1}" -f $_.Id, $_.MainModule.ModuleName } catch [System.ComponentModel.Win32Exception] {} } '@ function frmMain_Show { Add-Type -AssemblyName System.Windows.Forms [Windows.Forms.Application]::EnableVisualStyl...
PowerShellCorpus/PoshCode/IADsDNWithBinary Cmdlet_1.ps1
IADsDNWithBinary Cmdlet_1.ps1
//Adapted from code @ http://mow001.blogspot.com/2006/01/msh-snap-in-to-translate.html Thanks! using System; using System.ComponentModel; using System.Management.Automation; using System.Reflection; using System.Diagnostics; namespace space { // This class defines the properties of a snap-in [Ru...
PowerShellCorpus/PoshCode/Colorize Subversion SVN_2.ps1
Colorize Subversion SVN_2.ps1
#draw output function drawlines($colors, $lines) { foreach ($line in $lines) { $color = $colors[[string]$line[0]] if ($color) { write-host $line -Fore $color } else { write-host $line } } } # svn stat function ss { drawlines @{ "A"="Magenta"; "D"="Red"; "C"="Yellow"; "G"="Blue"; "M"="Cya...
PowerShellCorpus/PoshCode/WriteFileName_4.ps1
WriteFileName_4.ps1
# functions to print overwriting multi-line messages. Test script will accept a file/filespec/dir and iterate through all files in all subdirs printing a test message + file name to demostrate. # e.g. PS>.\\writefilename.ps1 c:\\ # call WriteFileName [string] # after done writing series of overwriting messages, cal...
PowerShellCorpus/PoshCode/Make a phone call_4.ps1
Make a phone call_4.ps1
<# .NOTES AUTHOR: Sunny Chakraborty(sunnyc7@gmail.com) WEBSITE: http://tekout.wordpress.com VERSION: 0.1 CREATED: 17th April, 2012 LASTEDIT: 17th April, 2012 Requires: PowerShell v2 or better .CHANGELOG 4/17/2012 Try passing powershell objects to PROTO API and pass the variables to .JS file P...
PowerShellCorpus/PoshCode/Invoke-AdvancedFunction..ps1
Invoke-AdvancedFunction..ps1
param(\n [Parameter(Mandatory = $true)]\n [ScriptBlock] $Scriptblock\n )\n\n## Invoke the scriptblock supplied by the user.\n& $scriptblock
PowerShellCorpus/PoshCode/UCS-ServiceProf-fromList.ps1
UCS-ServiceProf-fromList.ps1
<# ==================================================================== Author(s): Josh Atwell <josh.c.atwell@gmail.com> Link: www.vtesseract.com File: Get-UCSServiceProfileAssociations-FromList.ps1 Purpose: Gets Service Profile Associations for all UCS clusters provided in a list. If you want to v...
PowerShellCorpus/PoshCode/Use-Culture.ps1
Use-Culture.ps1
#############################################################################\n##\n## Use-Culture\n##\n## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n##\n#############################################################################\n\n<#\n\n.SYNOPSIS\n\nInvoke a scrip...
PowerShellCorpus/PoshCode/Get Twitter RSS Feed_1.ps1
Get Twitter RSS Feed_1.ps1
param ([String] $ScreenName) $client = New-Object System.Net.WebClient $idUrl = "https://api.twitter.com/1/users/show.json?screen_name=$ScreenName" $data = $client.DownloadString($idUrl) $start = 0 $findStr = '"id":' do { $start = $data.IndexOf($findStr, $start + 1) if ($start -gt 0) { $s...
PowerShellCorpus/PoshCode/09af4d5a-52a6-4d61-89dd-7b9016c3d1d7.ps1
09af4d5a-52a6-4d61-89dd-7b9016c3d1d7.ps1
<%@ Page language="c#" AutoEventWireup="true" Debug="true" %> <%@ Import Namespace="System" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Management.Automation.Runspaces" %> <%@ Import Namespace="System.Management.Automation" %> <%@ Import Namespace="System.Collections.ObjectModel" %> <s...
PowerShellCorpus/PoshCode/JSON _1.5.ps1
JSON _1.5.ps1
#requires -version 2.0 # Version History: # v 0.5 - First Public version # v 1.0 - Made ConvertFrom-Json work with arbitrary JSON # - switched to xsl style sheets for ConvertTo-JSON # v 1.1 - Changed ConvertFrom-Json to handle single item results # v 1.2 - CodeSigned to make a fellow geek happy # v 1.3 - ...
PowerShellCorpus/PoshCode/Out-DataTable_1.ps1
Out-DataTable_1.ps1
####################### <# .SYNOPSIS Creates a DataTable for an object .DESCRIPTION Creates a DataTable based on an objects properties. .INPUTS Object Any object can be piped to Out-DataTable .OUTPUTS System.Data.DataTable .EXAMPLE $dt = Get-Alias | Out-DataTable This example creates a DataTable fro...
PowerShellCorpus/PoshCode/VerifyCategoryRule_3.ps1
VerifyCategoryRule_3.ps1
## From Windows PowerShell Cookbook (O'Reilly) ## by Lee Holmes (http://www.leeholmes.com/guide) Set-StrictMode -Version Latest if($message.Body -match "book") { [Console]::WriteLine("This is a message about the book.") } else { [Console]::WriteLine("This is an unknown message.") }
PowerShellCorpus/PoshCode/ShowUI Clock _1.ps1
ShowUI Clock _1.ps1
New-UIWidget -AsJob -Content { $shadow = DropShadowEffect -Color Black -Shadow 0 -Blur 8 $now = Get-Date; StackPanel { TextBlock -Name "Time" ('{0:h:mm tt}' -f $now) -FontSize 108 -LineHeight 100 -LineStackingStrategy BlockLineHeight -Margin 0 -Padding 0 -Foreground White -Effect $shadow -FontFa...
PowerShellCorpus/PoshCode/WriteFileName_1.ps1
WriteFileName_1.ps1
# functions to print overwriting multi-line messages. Test script will accept a file/filespec/dir and iterate through all files in all subdirs printing a test message + file name to demostrate. # e.g. PS>.\\writefilename.ps1 c:\\ # call WriteFileName [string] # after done writing series of overwriting messages, cal...
PowerShellCorpus/PoshCode/New-Wrapper.ps1
New-Wrapper.ps1
function New-Wrapper { <# .Synopsis Encrypt a secret script to run from a new ps1 wrapper script. .Description Encrypt a secret script to run from a new ps1 wrapper script. A block diagram of how password is protected. http://bit.ly/jE1N7n The original template use...
PowerShellCorpus/PoshCode/0ba8cce5-b168-4f3d-a2e5-9c04920fb80e.ps1
0ba8cce5-b168-4f3d-a2e5-9c04920fb80e.ps1
# The $test variable can be pretty much whatever you want it to be, or with a little adjustment it isn't even necessary. # I just wanted to set it up like this for the $match variable later on $test=(get-folder testing|get-vm) #$data and the csv is where all the information lies that this script/s pulls $data=i...
PowerShellCorpus/PoshCode/Find Local Group Members_8.ps1
Find Local Group Members_8.ps1
# Author: Hal Rottenberg # Purpose: Find matching members in a local group # Used tip from RichS here: http://powershellcommunity.org/Forums/tabid/54/view/topic/postid/1528/Default.aspx # Change these two to suit your needs $ChildGroups = "Domain Admins", "Group Two" $LocalGroup = "Administrators" $MemberName...
PowerShellCorpus/PoshCode/Added_Deleted AD Objects_2.ps1
Added_Deleted AD Objects_2.ps1
#REQUIRES -pssnapin quest.activeroles.admanagement #REQUIRES -pssnapin Pscx begin { # Build variables $strSMTPServer = "xx.xx.xx.xx"; $strEmailFrom = "AD_Admin@yourdomain.com"; $strEmailTo = "admin@yourdomain.com"; $borders = "=" * 25; [int]$days = -60 function TombStonedObjects { # create Directory Se...
PowerShellCorpus/PoshCode/Out-Html.ps1
Out-Html.ps1
################################################################################ # Out-HTML - converts cmdlets help to HTML format # Based on Out-wiki by Dimitry Sotnikov (http://dmitrysotnikov.wordpress.com/2008/08/18/out-wiki-convert-powershell-help-to-wiki-format/) # # Modify the invocation line at the bottom of...
PowerShellCorpus/PoshCode/Get Exchange DB Stats_1.ps1
Get Exchange DB Stats_1.ps1
# requires -version 2.0 # # get-sgstats2010.ps1 # # returns various info about storage groups # # Author: rfoust@duke.edu # Modified: May 20, 2012 # # This has only been tested with Exchange 2010 # Use -nomountpoint if you don't use mountpoints in your environment param([string]$server=$env:computername.to...
PowerShellCorpus/PoshCode/Import-Iis-Log_2.ps1
Import-Iis-Log_2.ps1
param ( [Parameter( Mandatory=$true, Position = 0, ValueFromPipeline=$true, HelpMessage="Specifies the path to the IIS *.log file to import. You can also pipe a path to Import-Iss-Log." )] [ValidateNotNullOrEmpty()] [string] $Path, [Parameter( Position = 1, HelpMessage="Specifies the d...
PowerShellCorpus/PoshCode/Add-SqlClientAlias.ps1
Add-SqlClientAlias.ps1
####################### <# .SYNOPSIS Adds a SQL Server Client Alias by setting registry key. .DESCRIPTION Provides same functionality as cliconfg.exe GUI. Although there is a WMI provider to add client network aliases, the differences between SQL version make it diffult to use. This method creates the registry ke...
PowerShellCorpus/PoshCode/Test-WebDAV_3.ps1
Test-WebDAV_3.ps1
function Test-WebDav () { param ( $Url = "$( throw 'URL parameter is required.')" ) $xhttp = New-Object -ComObject msxml2.xmlhttp $xhttp.open("OPTIONS", $url, $false) $xhttp.send() if ( $xhttp.getResponseHeader("DAV") ) { $true } else { $false } }
PowerShellCorpus/PoshCode/Force WSUS Check.ps1
Force WSUS Check.ps1
# Powershell Script to force clients check into WSUS server # Import Active Directory PS Modules CMDLETS Import-Module ActiveDirectory $comps = Get-ADComputer -Filter {operatingsystem -like "*server*"} $cred = Get-Credential Foreach ($comp in $comps) { Invoke-Command -computername $comp.Name -credential...
PowerShellCorpus/PoshCode/357ba246-f3a1-4446-97ea-d22781827866.ps1
357ba246-f3a1-4446-97ea-d22781827866.ps1
function Write-ProgressForm { <# .SYNOPSIS Write-ProgressForm V1.0 GUI Replacement for PowerShell's Write-Progress command .DESCRIPTION GUI Replacement for PowerShell's Write-Progress command Uses same named parameters for drop-in replacement CAVEATS: You can't close the Form by clicking on it,...
PowerShellCorpus/PoshCode/Export top n SQLPlans_1.ps1
Export top n SQLPlans_1.ps1
<# ALZDBA SQLServer_Export_SQLPlans_SMO.ps1 Export top n consuming sqlplans via avg_worker_time (=cpu) for all databases of a given SQLServer (SQL2005+) Instance results in a number of .SQLPlan files and the consumption overview .CSV file #> #requires -version 2 #SQLServer instance $SQLInstance = 'uabe0db97\\ua...
PowerShellCorpus/PoshCode/Run-Query (SharePoint)_2.ps1
Run-Query (SharePoint)_2.ps1
function Run-Query($siteUrl, $queryText) { [reflection.assembly]::loadwithpartialname("microsoft.sharePOint") | out-null [reflection.assembly]::loadwithpartialname("microsoft.office.server") | out-null [reflection.assembly]::loadwithpartialname("microsoft.office.server.search") | out-null $s = [microsoft.share...
PowerShellCorpus/PoshCode/elevate-process (sudo).ps1
elevate-process (sudo).ps1
function elevate-process { $file, [string]$arguments = $args; $psi = new-object System.Diagnostics.ProcessStartInfo $file; $psi.Arguments = $arguments; $psi.Verb = "runas"; $psi.WorkingDirectory = get-location; [System.Diagnostics.Process]::Start($psi); } set-alias sudo elevate-process;
PowerShellCorpus/PoshCode/PerformanceHistory 2.52.ps1
PerformanceHistory 2.52.ps1
##requires -version 2.0 ## Get-PerformanceHistory.ps1 ############################################################################################################## ## Lets you see the amount of time recent commands in your history have taken ## History: ## v2.52 - added regex-based iteration counting to calculate...
PowerShellCorpus/PoshCode/ADFS troubleshooting_1.ps1
ADFS troubleshooting_1.ps1
<# This Script will check the MSOnline Office 365 setup. It will prompt the user running it to specify the credentials. It will then check compare the onsite information with the online information and inform the user if it is out of sync. #> $PSAdmin = Read-host "This script needs to be run as Administrator,...
PowerShellCorpus/PoshCode/SearchZIP_4.psm1 .ps1
SearchZIP_4.psm1 .ps1
function SearchZIPfiles { <# .SYNOPSIS Search for (filename) strings inside compressed ZIP or RAR files (V2.8). .DESCRIPTION In any directory containing a large number of ZIP/RAR compressed Web Page files this procedure will search each individual file name for simple text strings, listing both the source RAR...
PowerShellCorpus/PoshCode/Send-HTMLFormattedEmail_4.ps1
Send-HTMLFormattedEmail_4.ps1
################################################## # cmdlets ################################################## #------------------------------------------------- # Send-HTMLFormattedEmail #------------------------------------------------- # Usage: Send-HTMLFormattedEmail -? #------------------------------------...
PowerShellCorpus/PoshCode/New-ISEMenu_4.ps1
New-ISEMenu_4.ps1
Import-Module ShowUI Function New-ISEMenu { New-Grid -AllowDrop:$true -Name "ISEAddonCreator" -columns Auto, * -rows Auto,Auto,Auto,*,Auto,Auto -Margin 5 { New-Label -Name Warning -Foreground Red -FontWeight Bold -Column 1 ($target = New-TextBox -Name txtName -Column 1 -Row ($Row=1)) New-Label...
PowerShellCorpus/PoshCode/ShowUI Weather Widget.ps1
ShowUI Weather Widget.ps1
## And a slick weather widget using Yahoo's forecast and images New-UIWidget -AsJob { Grid { Rectangle -RadiusX 10 -RadiusY 10 -StrokeThickness 0 -Width 170 -Height 80 -HorizontalAlignment Left -VerticalAlignment Top -Margin "60,40,0,0" -Fill { LinearGradientBrush -Start "0.5,0" -End "0....
PowerShellCorpus/PoshCode/Get-Computer.ps1
Get-Computer.ps1
function Get-Computer { <# .Synopsis Retrieves basic information about a computer. .Description The Get-Computer cmdlet retrieves basic information such as computer name, domain or workgroup name, and whether or not the computer is on a workgroup or a domain for the local computer. .Exa...
PowerShellCorpus/PoshCode/chkhash_20.ps1
chkhash_20.ps1
# calculate SHA512 of file. function Get-SHA512([System.IO.FileInfo] $file = $(throw 'Usage: Get-MD5 [System.IO.FileInfo]')) { $stream = $null; $cryptoServiceProvider = [System.Security.Cryptography.SHA512CryptoServiceProvider]; $hashAlgorithm = new-object $cryptoServiceProvider $stream = $file.Open...
PowerShellCorpus/PoshCode/Send-Growl 1.0.ps1
Send-Growl 1.0.ps1
## This is the first version of a Growl module (just dot-source to use in PowerShell 1.0) ## Initially it only supports a very simple notice, and I haven't gotten callbacks working yet ## Coming soon: ## * Send notices to other PCs directly ## * Wrap the registration of new messages ## * Figure out the stupid ...
PowerShellCorpus/PoshCode/New-Zip_1.ps1
New-Zip_1.ps1
Function New-Zip { <# .SYNOPSIS Create a Zip File from any files piped in. .DESCRIPTION Requires that you have the SharpZipLib installed, which is available from http://www.icsharpcode.net/OpenSource/SharpZipLib/ .NOTES File Name : PowerZip.psm1 Author : Christophe CREMON (uxone) - http://powershel...
PowerShellCorpus/PoshCode/Route.psm1.ps1
Route.psm1.ps1
None
PowerShellCorpus/PoshCode/Get-SqlSpn.ps1
Get-SqlSpn.ps1
####################### <# .SYNOPSIS Gets MSQLSvc service principal names (spn) from Active Directory. .DESCRIPTION The Get-SqlSpn function gets SPNs for MSQLSvc services attached to account and computer objects .EXAMPLE Get-SqlSpn This command gets MSSQLSvc SPNs for the current domain .NOTES Adapted from ht...
PowerShellCorpus/PoshCode/Get-NestedGroups v_3.ps1
Get-NestedGroups v_3.ps1
Function Global:Get-NestedGroups { <# .SYNOPSIS Enumerate all AD group memberships of an account (including nested membership). .DESCRIPTION This script will return the AD group objects for each group the user is a member of. .PARAMETER UserName The username whose group memberships to find. .E...
PowerShellCorpus/PoshCode/NTFS ACLs Folder Tree_2.ps1
NTFS ACLs Folder Tree_2.ps1
####################################### # TITLE: listACL.ps1 # # AUTHOR: Santiago Fernandez Mu±oz # # # # DESC: This script generate a HTML # # report show all ACLs asociated with # # a Folder tree structure starting in # # root specified by the user ...
PowerShellCorpus/PoshCode/Get-RecurseMember_1.ps1
Get-RecurseMember_1.ps1
function Get-RecurseMember { <# .Synopsis Does a recursive search for unique users that are members of an AD group. .Description Recursively gets a list of unique users that are members of the specified group, expanding any groups that are members out into their member users. Note: Requires the Ques...
PowerShellCorpus/PoshCode/SQL-Select.ps1
SQL-Select.ps1
<# .SYNOPSIS Author:...Vidrine Date:.....2012/04/08 .DESCRIPTION Function uses the Microsoft SQL cmdlets 'Invoke-SQLcmd' to connect to a SQL database and run a SELECT statement. Results of the query are returned. Store returned results in a variable to be able to interact with them as an object. .PARAM s...
PowerShellCorpus/PoshCode/ConvertFrom-Hashtable_1.ps1
ConvertFrom-Hashtable_1.ps1
# function ConvertFrom-Hashtable { PARAM([HashTable]$hashtable,[switch]$combine) BEGIN { $output = New-Object PSObject } PROCESS { if($_) { $hashtable = $_; if(!$combine) { $output = New-Object PSObject } } $hashtable.GetEnumerator() | ForEach-Object { Add-Member -inputObject $objec...
PowerShellCorpus/PoshCode/Get-Netstat 1,_2.ps1
Get-Netstat 1,_2.ps1
$null, $null, $null, $null, $netstat = netstat -a -n -o [regex]$regexTCP = '(?<Protocol>\\S+)\\s+((?<LAddress>(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?))|(?<LAddress>\\[?[0-9a-fA-f]{0,4}(\\:([0-9a-fA-f]{0,4})){1,7}\\%?\\d?\\...
PowerShellCorpus/PoshCode/Get-Netstat 1,0.ps1
Get-Netstat 1,0.ps1
$null, $null, $null, $null, $netstat = netstat -a -n -o [regex]$regexTCP = '(?<Protocol>\\S+)\\s+(?<LocalAddress>\\S+)\\s+(?<RemoteAddress>\\S+)\\s+(?<State>\\S+)\\s+(?<PID>\\S+)' [regex]$regexUDP = '(?<Protocol>\\S+)\\s+(?<LocalAddress>\\S+)\\s+(?<RemoteAddress>\\S+)\\s+(?<PID>\\S+)' foreach ($net in $netstat) { ...
PowerShellCorpus/PoshCode/Import-Delimited 2.ps1
Import-Delimited 2.ps1
################################################################################ ## Convert-Delimiter - A function to convert between different delimiters. ## E.g.: commas to tabs, tabs to spaces, spaces to commas, etc. ################################################################################ ## Written pri...
PowerShellCorpus/PoshCode/Autoload Module _1.2.ps1
Autoload Module _1.2.ps1
#Requires -Version 2.0 ## Automatically load functions from scripts on-demand, instead of having to dot-source them ahead of time, or reparse them from the script every time. ## Provides significant memory benefits over pre-loading all your functions, and significant performance benefits over using plain scripts. Ca...
PowerShellCorpus/PoshCode/Import-GmailFilterXml.ps1
Import-GmailFilterXml.ps1
param ( $Path ) [xml]$flt = Get-Content -Path $Path $title = $flt.feed.title $author = $flt.feed.author.name $output = @() foreach ( $entry in $flt.feed.entry ) { foreach ( $property in $entry.property ) { foreach ($item in $property) { $process = "" | select Id, Updated, Name, Value $process.Id = ...
PowerShellCorpus/PoshCode/ScriptingAgentConfig.xml.ps1
ScriptingAgentConfig.xml.ps1
<?xml version="1.0" encoding="UTF-8" ?> <Configuration version="1.0"> <Feature Name="MailboxProvisioningDatabase" Cmdlets="new-mailbox"> <ApiCall Name="ProvisionDefaultProperties"> #Regex switch to decide mailboxdatabase based on the user specified Name-attribute switch -regex (($provisioningHandler.UserSpec...
PowerShellCorpus/PoshCode/get-smtpconnections.ps1
get-smtpconnections.ps1
param ( $logpath = "C:\\WINDOWS\\system32\\LogFiles\\SMTPSVC1" # can also be fed by "gci $logpath | select basename" but then all logfiles would be read $logfiles = @("ex130213.log","ex130214.log") $regex = "(?:[0-9]{1,3}\\.){3}[0-9]{1,3}" ) $smtphosts = @() foreach ($logFile in $logfiles){ # can also be iter...
PowerShellCorpus/PoshCode/2311f39b-7495-4f1a-9a8b-bc425f057624.ps1
2311f39b-7495-4f1a-9a8b-bc425f057624.ps1
function Get-EasterWestern { Param( [Parameter(Mandatory=$true)] [int] $Year ) $a = $Year % 19 $b = [Math]::Floor($Year / 100) $c = $Year % 100 $d = [Math]::Floor($b / 4) $e = $b % 4 $f = [Math]::Floor(($b + 8) / 25) $g = [Math]::Floor((($b - $f + 1) / 3)) $h = ((19 ...
PowerShellCorpus/PoshCode/Get-Netstat 1,_1.ps1
Get-Netstat 1,_1.ps1
$null, $null, $null, $null, $netstat = netstat -a -n -o [regex]$regexTCP = '(?<Protocol>\\S+)\\s+((?<LAddress>(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?))|(?<LAddress>\\[?[0-9a-fA-f]{0,4}(\\:([0-9a-fA-f]{0,4})){1,7}\\%?\\d?\\...
PowerShellCorpus/PoshCode/PS2WCF_3.ps1
PS2WCF_3.ps1
# Call WCF Services With PowerShell V1.0 22.12.2008 # # by Christian Glessner # Blog: http://www.iLoveSharePoint.com # Twitter: http://twitter.com/cglessner # Codeplex: http://codeplex.com/iLoveSharePoint # # requires .NET 3.5 # load WCF assemblies [void][System.Reflection.Assembly]::LoadWithPartialName("Sy...
PowerShellCorpus/PoshCode/336b281d-5018-4ca9-a92e-baf5152f59a3.ps1
336b281d-5018-4ca9-a92e-baf5152f59a3.ps1
function Get-Installed { <# .SYNOPSIS This function lists data found in the registry associated with installed programs. .DESCRIPTION Describe the function in more detail Author: Stan Miller .EXAMPLE Get all apps whose display names start with a specific string and display all valuenam...
PowerShellCorpus/PoshCode/TabExpansion for V2CTP_5.ps1
TabExpansion for V2CTP_5.ps1
## Tab-Completion ################# ## For V2CTP3. ## This won't work on V1 and V2CTP and V2CTP2. ## Please dot souce this script file. ## In first loading, it may take a several minutes, in order to generate ProgIDs and TypeNames list. ## ## What this can do is: ## ## [datetime]::n<tab> ## [datetime]::now.d...
PowerShellCorpus/PoshCode/Set-Domain_5.ps1
Set-Domain_5.ps1
function Set-Domain { param( [switch]$help, [string]$domain=$(read-host "Please specify the domain to join"), [System.Management.Automation.PSCredential]$credential = $(Get-Credential) ) $usage = "`$cred = get-credential `n" $usage += "Set-Domain -domain MyDomain -credential `$cred`n" if ($hel...
PowerShellCorpus/PoshCode/Xml Module 5.0.ps1
Xml Module 5.0.ps1
#requires -version 2.0 # Improves over the built-in Select-XML by leveraging Remove-XmlNamespace http`://poshcode.org/1492 # to provide a -RemoveNamespace parameter -- if it's supplied, all of the namespace declarations # and prefixes are removed from all XML nodes (by an XSL transform) before searching. # IMP...
PowerShellCorpus/PoshCode/Get-Arguments.ps1
Get-Arguments.ps1
##############################################################################\n##\n## Get-Arguments\n##\n## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n##\n##############################################################################\n\n<#\n\n.SYNOPSIS\n\nUses comma...
PowerShellCorpus/PoshCode/20498039475807687.ps1
20498039475807687.ps1
# Requires a connection to Exchange Server, or Exchange Management Shell $s = New-PSSession -ConfigurationName Microsoft.Exchange -Name ExchMgmt -ConnectionUri http://ex14.domain.local/PowerShell/ -Authentication Kerberos Import-PSSession $s # Get all Client Access Server properties for all mailboxes with an Activ...
PowerShellCorpus/PoshCode/Sort-ISE.ps1
Sort-ISE.ps1
function Sort-ISE () { <# .SYNOPSIS ISE Extension sort text starting at column $start comparing the next $length characters .DESCRIPTION ISE Extension sort text starting at column $start comparing the next $length characters Leftmost column is column 1 .NOTES File Name : Sort_IS...
PowerShellCorpus/PoshCode/Import-CSV.ps1
Import-CSV.ps1
Param($file,$headers) # Check for Input and fill $data if($input){$data = @();$input | foreach-Object{$data += $_}} # Check for File and Test the Path if($file) { if(Test-Path $file) { # Check for Headers... if none use import-csv if(!$headers) { import-Csv $data...
PowerShellCorpus/PoshCode/Test-SqlConnection_1.ps1
Test-SqlConnection_1.ps1
####################### <# Version History v1.0 - Chad Miller - Initial release v1.1 - Chad Miller - Fixed issues, added colorized HTML output #> Add-Type -AssemblyName System.Xml.Linq $Script:CMServer = 'MyServer' ####################### function Test-Ping { param([Parameter(Mandatory=$true, V...
PowerShellCorpus/PoshCode/Get-WindowsExperience_1.ps1
Get-WindowsExperience_1.ps1
function Get-WindowsExperienceRating { #.Synopsis # Gets the Windows Experience Ratings #.Parameter ComputerName # The name(s) of the computer(s) to get the Windows Experience (WinSat) numbers for. [CmdletBinding()] param( [Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [string[...
PowerShellCorpus/PoshCode/Get-MWSOrder_2.ps1
Get-MWSOrder_2.ps1
// -------------------------------------------------------------------------------------------------------------------- // <copyright file="GetOrderCmdlet.cs" company="Huddled Masses"> // Copyright (c) 2011 Joel Bennett // </copyright> // <summary> // Defines the Get-Order Cmdlet for Amazon Marketplace Orders ...
PowerShellCorpus/PoshCode/Move-LockedFile.ps1
Move-LockedFile.ps1
##############################################################################\n##\n## Move-LockedFile\n##\n## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n##\n##############################################################################\n\n<#\n\n.SYNOPSIS\n\nRegister...
PowerShellCorpus/PoshCode/PurgeFile script..ps1
PurgeFile script..ps1
<# .SYNOPSIS Purgefiles - recursively remove files with given extension and maximum age from a given path. .DESCRIPTION Read the synopsis Example PurgeFiles.psq -path C:\\temp -ext .tmp -max 24 .EXAMPLE PurgeFiles.psq -path C:\\temp -ext .tmp -max 24 #> # HISTORY # 2010/01/29 # rluiten Created pa...
PowerShellCorpus/PoshCode/5e6d3b3f-4cf8-4c50-95a0-a300d6f0b630.ps1
5e6d3b3f-4cf8-4c50-95a0-a300d6f0b630.ps1
# to load c:\\powershellscripts\\cluster_utils.ps1 if it isn't already loaded @@. require cluster_utils Here are the functions: $global:loaded_scripts=@{} function require([string]$filename){ if (!$loaded_scripts[$filename]){ . c:\\powershellscripts\\$filename $loaded_scripts[$filename]...
PowerShellCorpus/PoshCode/Paraimpu.ps1
Paraimpu.ps1
# This requires JSON 1.7 ( http://poshcode.org/2930 ) and the HttpRest ( http://poshcode.org/2097 ) modules # It's a first draft at Paraimpu cmdlets # I'm not sure yet that using Paraimpu with my Chumby gets me what I want, since it only shows one item and can't go back to old ones. # # YOU SHOULD SET THE $Token ...
PowerShellCorpus/PoshCode/Manage ASP_5.NET Providers.ps1
Manage ASP_5.NET Providers.ps1
# Manage_ASP_NET_Providers.ps1 # by Chistian Glessner # http://iLoveSharePoint.com # If you want to change the app config you have to restart PowerShell param($appConfigPath=$null) # App config path have to be set before loading System.Web.dll [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $appC...
PowerShellCorpus/PoshCode/New-ISEMenu_5.ps1
New-ISEMenu_5.ps1
Import-Module ShowUI Function New-ISEMenu { New-Grid -AllowDrop:$true -Name "ISEAddonCreator" -columns Auto, * -rows Auto,Auto,Auto,*,Auto,Auto -Margin 5 { New-Label -Name Warning -Foreground Red -FontWeight Bold -Column 1 ($target = New-TextBox -Name txtName -Column 1 -Row ($Row=1)) New-Label...
PowerShellCorpus/PoshCode/0dbcab33-47ec-4c68-98cd-b9e906786e5a.ps1
0dbcab33-47ec-4c68-98cd-b9e906786e5a.ps1
$WarningPreference = "SilentlyContinue" $password = Get-Content C:\\securestring.txt | convertto-securestring $username = "PROD\\administrator" $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password $uucenter = "uuoresund.dk" $totalSize = 0 $session = ...
PowerShellCorpus/PoshCode/WpfBindingHelper.ps1
WpfBindingHelper.ps1
using System; using System.Windows; using System.ComponentModel; using System.Windows.Markup; using System.Windows.Data; using System.Globalization; namespace PoshWpf { public class BindingConverter : ExpressionConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type de...
PowerShellCorpus/PoshCode/825cfd12-39f8-4fa2-9843-880b0ab0e880.ps1
825cfd12-39f8-4fa2-9843-880b0ab0e880.ps1
$Raw = Whoami /groups $Groups = $Raw | ?{ $_ -match "Enabled Group" } | %{$_.Split(" ,")[0] } | ?{ $_ -like "*\\*" }| Sort $Groups
PowerShellCorpus/PoshCode/Connect-AccessDB_3.ps1
Connect-AccessDB_3.ps1
# Functions for connecting to and working with Access databases # Matt Wilson # May 2009 function Connect-AccessDB ($global:dbFilePath) { # Test to ensure valid path to database file was supplied if (-not (Test-Path $dbFilePath)) { Write-Error "Invalid Access database path specified. Please supply full a...
PowerShellCorpus/PoshCode/Get-Answer.ps1
Get-Answer.ps1
##############################################################################\n##\n## Get-Answer\n##\n## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n##\n##############################################################################\n\n<#\n\n.SYNOPSIS\n\nUses Bing Ans...
PowerShellCorpus/PoshCode/Add-ByteFormat.ps1
Add-ByteFormat.ps1
function Add-ByteFormat { <# .Synopsis Function to make display of custom properties more human-readable. .Description With help of this function you will be able to force nice display of numeric data. It's using best possible unit of measure for *bytes sizes. If input...
PowerShellCorpus/PoshCode/Ping-Host_1.ps1
Ping-Host_1.ps1
function Ping-Host {param( [string]$HostName, [int32]$Requests = 3) for ($i = 1; $i -le $Requests; $i++) { $Result = Get-WmiObject -Class Win32_PingStatus -ComputerName . -Filter "Address='$HostName'" Start-Sleep -Seconds 1 if ($Result.StatusCode -ne 0) {return $FALSE} } return $TRUE }
PowerShellCorpus/PoshCode/Get-MSDNInfo.ps1
Get-MSDNInfo.ps1
function Get-MSDNInfo { <# .SYNOPSIS Opens the MSDN web page of an object member: type, method or property. .DESCRIPTION The Get-MSDNInfo function enables you to quickly open a web browser to the MSDN web page of any given instance of a .NET object. You can also refer to Get-MSDNInf...
PowerShellCorpus/PoshCode/WakeOnLan.ps1
WakeOnLan.ps1
#wakeonlan $computer function WakeOnLan($computer) { $select=$select |where-object {$_.computername -eq $computer} |Select-Object mac if ($select.mac -eq $null) { echo "workstation not found.epic fail. use all to wake'em all" } else { $select.mac -match "(..)(..)(..)(..)(..)(..)" | out-null $mac...
PowerShellCorpus/PoshCode/Execute-RunspaceJob.ps1
Execute-RunspaceJob.ps1
<# .SYNOPSIS Executes a set of parameterized script blocks asynchronously using runspaces, and returns the resulting data. .DESCRIPTION Encapsulates generic logic for using Powershell background runspaces to execute parameterized script blocks in an efficient, multi-threaded fashion. For detailed ex...
PowerShellCorpus/PoshCode/Move-Mailbox _1.ps1
Move-Mailbox _1.ps1
param( #distribution group holding usermailbox(es) [string] $DistGroup = "XC2010Move", #move requests per batch/script run [int] $BatchCount = 5 ) #remove user(s) without mailbox Get-DistributionGroupMember $DistGroup | get-user -Filter {Recipienttype -eq "User"} -EA SilentlyContinue | Remove-DistributionGrou...
PowerShellCorpus/PoshCode/Get-Parameter_7.ps1
Get-Parameter_7.ps1
function Get-Parameter ( $Cmdlet, [switch]$ShowCommon, [switch]$Full ) { foreach ($paramset in (Get-Command $Cmdlet).ParameterSets){ $Output = @() foreach ($param in $paramset.Parameters) { if ( !$ShowCommon ) { if ($param.aliases -match "vb|db|ea|wa|ev|wv|ov|ob|wi|cf") { continue } } $process ...
PowerShellCorpus/PoshCode/Get-MIX10Video.ps1
Get-MIX10Video.ps1
#requires -version 2.0 PARAM ( [Parameter(Position=1, Mandatory=$true)] [ValidateSet("wmv","wmvhigh","ppt", "mp4")] [String]$MediaType, [string]$Destination = $PWD ) if( ([System.Environment]::OSVersion.Version.Major -gt 5) -and -not ( # Vista and ... new-object Security.Principal.WindowsPrinci...
PowerShellCorpus/PoshCode/Sort-ISE_Boots.ps1
Sort-ISE_Boots.ps1
function Sort-ISE () { <# .SYNOPSIS ISE Extension sort text starting at column $start comparing the next $length characters .DESCRIPTION ISE Extension sort text starting at column $start comparing the next $length characters Leftmost column is column 1 .NOTES File Name : Sort-IS...
PowerShellCorpus/PoshCode/Folder inheritance.ps1
Folder inheritance.ps1
# setup the test folders md c:\\grandfather\\father\\son md c:\\grandmother\\mother\\daughter # By default the folders will inherit ACLs from the C: drive # To toggle it or change it to the desired setting # Will force the inheritance from parent $inheritance = get-acl c:\\grandmother $inhe...
PowerShellCorpus/PoshCode/Combine-CSV Function.ps1
Combine-CSV Function.ps1
function Combine-CSV{ <# .Synopsis Combines similar CSV files into a single CSV File .Description Function will combine common .CSV files into one large file. CSV files should have same header. This script is intended to aid when doing large reports across a large environment. .Parameter S...