full_path
stringlengths
31
232
filename
stringlengths
4
167
content
stringlengths
0
48.3M
PowerShellCorpus/PoshCode/ISE-Comments_1.ps1
ISE-Comments_1.ps1
#requires -version 2.0 ## ISE-Comments module v 1.1 ############################################################################################################## ## Provides Comment cmdlets for working with ISE ## ConvertTo-BlockComment - Comments out selected text with <# before and #> after ## ConvertTo-BlockUn...
PowerShellCorpus/PoshCode/Invoke-ComplexDebuggerSc.ps1
Invoke-ComplexDebuggerSc.ps1
#############################################################################\n##\n## Invoke-ComplexDebuggerScript\n##\n## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n##\n##############################################################################\n\n<#\n\n.SYNOPSIS...
PowerShellCorpus/PoshCode/Set-RemoteRegistryKeyPro.ps1
Set-RemoteRegistryKeyPro.ps1
##############################################################################\n##\n## Set-RemoteRegistryKeyProperty\n##\n## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n##\n##############################################################################\n\n<#\n\n.SYNOPS...
PowerShellCorpus/PoshCode/ConvertTo-PseudoType_2.ps1
ConvertTo-PseudoType_2.ps1
#function ConvertTo-PseudoType { <# .Synopsis Convert an object to a custom PSObject wiith robust type information .Parameter TypeName The name(s) of the PseudoType(s) to be inserted into the objects for the sake of formatting .Parameter Mapping A Hashtable of property names to types (or conversion ...
PowerShellCorpus/PoshCode/Convert-PowerPack2Ps_1.ps1
Convert-PowerPack2Ps_1.ps1
####################################################################### # Convert-PowerPack2Ps1 # # Converts PowerGUI .PowerPack files to ps1 PowerShell script library # v1 - raw conversion, no name changes, only script elements converted ###################################################################### # E...
PowerShellCorpus/PoshCode/Custom Object Factory Te.ps1
Custom Object Factory Te.ps1
<# .SYNOPSIS A template for a function that creates a PSObject .DESCRIPTION If you find yourself creating a lot of custom PSObjects with lots of Properties, this template may help save you some typing. It discovers the function paramters, and uses them to create a hash that is splatted against a (new-object ps...
PowerShellCorpus/PoshCode/New-Exch2010NlbCluster_1.ps1
New-Exch2010NlbCluster_1.ps1
########################################################################### # # NAME: New-Exch2010NlbCluster.ps1 # # AUTHOR: Jan Egil Ring # EMAIL: jer@powershell.no # # COMMENT: Script to create a NLB-cluster for the CAS/HUB-roles in Exchange Server 2010. # For more details, see the following blog-pos...
PowerShellCorpus/PoshCode/default.config.ps1
default.config.ps1
<!-- An example log4net config (Save as default.config) --> <log4net> <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender"> <mapping> <level value="ERROR" /> <foreColor value="Red, HighIntensity" /> <backColor value="White, HighIntensity...
PowerShellCorpus/PoshCode/Join-String.ps1
Join-String.ps1
#.Synopsis # Joins array elements together using a specific string separator #.Example # $Env:Path = ls | ? {$_.PSIsContainer} | Select -expand FullName | Join ";" -Append $Env:Path #.Example # get-process | select -expand name | join "," # function Join-String { param ( [string]$separator, [string...
PowerShellCorpus/PoshCode/Get-Parameter_8.ps1
Get-Parameter_8.ps1
function Get-Parameter ( $Cmdlet, [switch]$ShowCommon, [switch]$Full ) { $command = Get-Command $Cmdlet -ea silentlycontinue # resolve aliases (an alias can point to another alias) while ($command.CommandType -eq "Alias") { $command = Get-Command ($command.definition) } if (-not $command) { return }...
PowerShellCorpus/PoshCode/Create datastore by LUN .ps1
Create datastore by LUN .ps1
function New-DatastoreByLun { param( [string]$vmHost, [string]$hbaId, [int]$targetId, [int]$lunId, [string]$dataStoreName ) $view = Get-VMHost $vmHost | get-view $lun = $view.Config.StorageDevice.ScsiTopology | ForEach-Object { $_.Adapter } | Where-Object {$_.Key -match $hbaId} | ForEach-Object {$_.Target} | ...
PowerShellCorpus/PoshCode/PWD Expiration Email.ps1
PWD Expiration Email.ps1
#Active Directory Group Name To Be Edited #Load Active Directory Module if(@(get-module | where-object {$_.Name -eq "ActiveDirectory"} ).count -eq 0) {import-module ActiveDirectory} # get domain maximumPasswordAge value $MaxPassAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.days if($MaxPassAge -le ...
PowerShellCorpus/PoshCode/New-Struct_2.ps1
New-Struct_2.ps1
## New-Struct ## Creates a Struct class and emits it into memory ## The Struct includes a constructor which takes the parameters in order... ## ## Usage: ## # Assuming you have a csv file with no header and columns: artist,name,length ## New-Struct Song @{ ## Artist=[string]; ## Name=[string]; ...
PowerShellCorpus/PoshCode/Excel Auto-frontend.ps1
Excel Auto-frontend.ps1
Function New-DummyVM { param( [Parameter(Mandatory=$true,HelpMessage="Target Host")] [VMware.VimAutomation.Types.VMHost] $TargetHost, [Parameter(Mandatory=$true,HelpMessage="Target Host")] [VMware.VimAutomation.Types.ResourcePool] $ResourcePool, [Parameter(Mandatory=$true,HelpMessage="New VM Name")]...
PowerShellCorpus/PoshCode/MailChimp GetDistributio.ps1
MailChimp GetDistributio.ps1
#Author: Tozzi June 2012 #OriginalAuthor: Ant B 2012 #Purpose: Batch feed recipients to MailChimp $ie = new-object -com "InternetExplorer.Application" # Vars for building the URL $apikey = "api-key-from-mailchimp" $listid = "list-id-from-mailchimp" # Important is to use correct MailChimp data centre. In th...
PowerShellCorpus/PoshCode/get windows product key_1.ps1
get windows product key_1.ps1
function get-windowsproductkey([string]$computer) { $Reg = [WMIClass] ("\\\\" + $computer + "\\root\\default:StdRegProv") $values = [byte[]]($reg.getbinaryvalue(2147483650,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion","DigitalProductId").uvalue) $lookup = [char[]]("B","C","D","F","G","H","J","K","M","P","Q","R"...
PowerShellCorpus/PoshCode/Unlock & Password Reset.ps1
Unlock & Password Reset.ps1
<# Author: Matt Schmitt Date: 11/28/12 Version: 1.0 From: USA Email: ithink2020@gmail.com Website: http://about.me/schmittmatt Twitter: @MatthewASchmitt Description A script for forwarding and unforwarding email for users in Office 365. #> Import-Module ActiveD...
PowerShellCorpus/PoshCode/Start-Timer_1.ps1
Start-Timer_1.ps1
A syntax error on your $Status array definition - you forgot the braces around the elements; [string[]]$status=("Cooking","Burning") cheers, yeatsie ## Start-Timer.ps1 ## A kitchen timer script with visible countdown and customizable audio alert and messages ################################################...
PowerShellCorpus/PoshCode/Start-IRCJabberBridge_1.ps1
Start-IRCJabberBridge_1.ps1
@@## Depends on the PoshXmpp.dll from http://CodePlex.com/PoshXmpp @@#requires -pssnapin PoshXmpp ########################################################################################## # @Author: Joel Bennnett # @Usage: # Start-JabberMirror.ps1 User@JabberServer.com Password "groupchat@oneserver.com" "groupcha...
PowerShellCorpus/PoshCode/get-DiskVolumeInfo_1.ps1
get-DiskVolumeInfo_1.ps1
function get-DiskVolumeInfo { <# .SYNOPSIS Returns information about disk volumes including freespace .DESCRIPTION Returns information about disk volumes including freespace .EXAMPLE show-InnerException ExceptionObject Shows the in...
PowerShellCorpus/PoshCode/Snippet Compiler_4.ps1
Snippet Compiler_4.ps1
$def = $(if ((gi .).FullName -eq (gi .).Root) { ([string](gi .).Root).TrimEnd("\\") } else { (gi .).FullName } ) ################################################################################################## function Get-CursorPoint { $x = $rtbEdit.SelectionStart - $...
PowerShellCorpus/PoshCode/finddupe_22.ps1
finddupe_22.ps1
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 try { $stream = $file.OpenRead() } ...
PowerShellCorpus/PoshCode/Check-ClusterPatches.ps1
Check-ClusterPatches.ps1
## Check-ClusterPatches.ps1 param($ClusterNode=$Env:ComputerName) $Patches = @{} $PatchList = $Null $PatchListComplete = $Null $Results = @() Write-Host "Getting Nodes via WMI..." -foregroundcolor Green $Nodes = Get-WmiObject -computerName $ClusterNode -namespace ROOT\\MSCluster -class MSCluster_Node | S...
PowerShellCorpus/PoshCode/Convert-ToCHexString.ps1
Convert-ToCHexString.ps1
function Convert-ToCHexString { param([String] $input $ans = '' [System.Text.Encoding]::ASCII.GetBytes($str) | % { $ans += "0x{0:X2}, " -f $_ } return $ans.Trim(',',' ') }
PowerShellCorpus/PoshCode/Hash Checker_2.ps1
Hash Checker_2.ps1
#.Synopsis # Test the HMAC hash(es) of a file #.Description # Takes the HMAC hash of a file using specified algorithm, and optionally, compare it to a baseline hash #.Example # Test-Hash npp.5.3.1.Installer.exe -HashFile npp.5.3.1.release.md5 # # Searches the provided hash file for a line matching the "...
PowerShellCorpus/PoshCode/Page-Output 1.1.ps1
Page-Output 1.1.ps1
## Page (aka More, aka Page-Output) ################################################################################################### ## This is like a (very simple) "more" script for PowerShell ... ## The problem with it is that you're paging by a count of objects, not by how many lines of text ## they'll outp...
PowerShellCorpus/PoshCode/Edit-File in Notepad++_1.ps1
Edit-File in Notepad++_1.ps1
<# .Synopsis Open a file for editing in notepad++ .Description Opens one or more files in Notepad++, passing all the switches each time. Accepts filenames on the pipeline .Notes I took the "no" off the parameters, because in PowerShell you only need to enter just enough of the parameter name to differ...
PowerShellCorpus/PoshCode/Speech Recognition.ps1
Speech Recognition.ps1
$null = [Reflection.Assembly]::LoadWithPartialName("System.Speech") ## Create the two main objects we need for speech recognition and synthesis if(!$Global:SpeechModuleListener){ ## For XP's sake, don't create them twice... $Global:SpeechModuleSpeaker = new-object System.Speech.Synthesis.SpeechSynthesizer $...
PowerShellCorpus/PoshCode/Send mail to BCC using P.ps1
Send mail to BCC using P.ps1
<# .SYNOPSIS Send mail to BCC using PowerShell .DESCRIPTION This script is a re-developed MSDN Sample using PowerShell. It creates an email message then sends it with a BCC. .NOTES File Name : Send-BCCMail.ps1 Author : Thomas Lee - tfl@psp.co.uk Requires : PowerShell V2 CTP3 .LINK O...
PowerShellCorpus/PoshCode/Invoke-NamedParameters.ps1
Invoke-NamedParameters.ps1
Function Invoke-NamedParameters { <# .SYNOPSIS Invokes a method using named parameters. .DESCRIPTION A function that simplifies calling methods with named parameters to make it easier to deal with long signatures and optional parameters. This is particularly helpful for COM objects. .PARAMETER Object ...
PowerShellCorpus/PoshCode/MWE_UsageSample.psm1.ps1
MWE_UsageSample.psm1.ps1
# ModuleWriteErrorUsageExample.psm1 # To use this you need to have the ModuleWriteError module loaded. #Import-Module c:\\scripts\\ModuleWriteError # Also:: Using $ErrorView = "CategoryView" is useful too. function Get-Foo { [CmdletBinding()] param( [string]$name, [switch]$interrupt ) Process...
PowerShellCorpus/PoshCode/Log4Net_1.xslt.ps1
Log4Net_1.xslt.ps1
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://logging.apache.org/log4net/schemas/log4net-events-1.2" version="1.0"> <xsl:output method="html" indent="yes" encoding="UTF-8"/> <xsl:template match="events">...
PowerShellCorpus/PoshCode/26d9a40a-d77f-4500-a0b2-5d0d79606685.ps1
26d9a40a-d77f-4500-a0b2-5d0d79606685.ps1
$screen = " You see here a virtual switch. ------------ ------ #...........| |....| --------------- ###------------ |...(| |..%...........|########## ###-@...| ...
PowerShellCorpus/PoshCode/Backup-ModifiedGPOs_1.ps1
Backup-ModifiedGPOs_1.ps1
###########################################################################" # # NAME: Backup-ModifiedGPOs.ps1 # # AUTHOR: Jan Egil Ring # EMAIL: jan.egil.ring@powershell.no # # COMMENT: All Group Policy Objects modified in the specified timespan are backup up to the specified backup path. # For more d...
PowerShellCorpus/PoshCode/Convert-ToMP_1.ps1
Convert-ToMP_1.ps1
param([String] $inputPath, [String] $wildcard, [String] $outputPath = $inputPath) gci -path $inputPath\\$wildcard | % { $outputFile = Join-Path $outputPath ($_.Name.Replace($_.Extension, '.mp3')) vlc -I dummy $_.FullName ":sout=#transcode{acodec=mp3,ab=128,channels=6}:standard{access=file,mux=asf,dst=$outp...
PowerShellCorpus/PoshCode/e61c6c2a-be74-4a09-8b96-80d2469d4644.ps1
e61c6c2a-be74-4a09-8b96-80d2469d4644.ps1
CREATE LOGIN [vCenter_Owner] WITH PASSWORD=N'KVx$!|mhQ^', CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF GO --Modify Drive and size to match your environment CREATE DATABASE [vCenter] ON PRIMARY ( NAME = N'vCenter', FILENAME = N'S:\\Data\\vCenter.mdf' , SIZE = 100MB , MAXSIZE = UNLIMITED, FILEGROWTH = 10%) LOG ON (...
PowerShellCorpus/PoshCode/Get-mDatastoreList.ps1
Get-mDatastoreList.ps1
Function Get-mDatastoreList { #Parameter- Name of the VMware cluster to choose a datastore from. param($Cluster) #get alphabetically last ESX host in the VMware cluster (it's likely the last host added to the cluster, so this might smoke out any problems) $VMH = get-vmhost -Location $cluster | Where-Object { ($_....
PowerShellCorpus/PoshCode/Run-Defrag_2.ps1
Run-Defrag_2.ps1
# Run-Defrag # Defragments the targeted hard drives. # # Args: # $server: A target Server 2003 or 2008 system # $drive: An optional drive letter. If this is blank then all # drives are defragmented # $force: If this switch is set then a defrag will be forced # even if the drive is lo...
PowerShellCorpus/PoshCode/Set-IPAddress_7.ps1
Set-IPAddress_7.ps1
# corrected version - $mask variable corrected to match in both places function Set-IPAddress { param( [string]$networkinterface =$(read-host "Enter the name of the NIC (ie Local Area Connection)"), [string]$ip = $(read-host "Enter an IP Address (ie 10.10.10.10)"), [string]$mask = $(read-host "Enter the sub...
PowerShellCorpus/PoshCode/Add-Namespace v1.1.ps1
Add-Namespace v1.1.ps1
trap [System.Management.Automation.RuntimeException] { $entryException = $_ if ($_.CategoryInfo.Category -eq [System.Management.Automation.ErrorCategory]::InvalidOperation) { if ($_.FullyQualifiedErrorId -eq "TypeNotFound") { $targetName = $_.CategoryInfo.TargetName ...
PowerShellCorpus/PoshCode/Get-OUComputerNames.ps1
Get-OUComputerNames.ps1
param( [switch]$Help, [string] $OU ) $usage = @' Get-OUComputerNames usage : .\\Get-OUComputerNames.ps1 "OU=TESTOU,dc=domain,dc=com" returns : the names of computers in Active Directory (AD) that recursively match a given LDAP query author : Nathan Hartley '@ if ($help) {Write-Host $usage;br...
PowerShellCorpus/PoshCode/TreeView Sample.ps1
TreeView Sample.ps1
Add-Type -AssemblyName presentationframework function view-TextFiles ($dir = '.') { # Create WPF Form from XAML file and bind Controls to variables $path = Resolve-Path $dir $Form=[Windows.Markup.XamlReader]::Load([IO.File]::OpenText('c:\\scripts\\window.xaml').basestream) $ListBox = $form.Fin...
PowerShellCorpus/PoshCode/hex2dec_1.ps1
hex2dec_1.ps1
@echo off ::unequal symbols for %%i in ("!", "x") do if "%1" equ "%%~i" goto:error ::display help information args for %%i in ("-h", "/h", "-help", "/help") do ( if "%1" equ "%%~i" goto:help ) if "%1" equ "-?" goto:help if "%1" equ "/?" goto:help ::interactive mode if "%1" equ "" ( if not defi...
PowerShellCorpus/PoshCode/All Exchange 2003 Server.ps1
All Exchange 2003 Server.ps1
[Array]$ExchSrvs = @("") [String]$StrFilter = “(objectCategory=msExchExchangeServer)” $objRootDSE = [ADSI]“LDAP://RootDSE” [String]$strContainer = $objRootDSE.configurationNamingContext $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-object ` System.DirectoryServ...
PowerShellCorpus/PoshCode/Get-MyPublicIPAddress.ps1
Get-MyPublicIPAddress.ps1
<# .SYNOPSIS Gets the public IP address that represents your computer on the internet. .DESCRIPTION The Get-MyPublicIPAddress script uses DNS-O-Matic, an OpenDNS resource, to retreive the public IP address that represents your computer on the internet. .EXAMPLE Get-MyPublicIPAddress 1.1.1.1 ...
PowerShellCorpus/PoshCode/Get-OwnerReport_1.ps1
Get-OwnerReport_1.ps1
############################################################################## ## ## Get-OwnerReport ## ## From Windows PowerShell Cookbook (O'Reilly) ## by Lee Holmes (http://www.leeholmes.com/guide) ## ############################################################################## <# .SYNOPSIS Gets a l...
PowerShellCorpus/PoshCode/Test-UserCredential_5.ps1
Test-UserCredential_5.ps1
function Test-UserCredential { [CmdletBinding(DefaultParameterSetName = "set1")] [OutputType("set1", [System.Boolean])] [OutputType("PSCredential", [System.Boolean])] param( [Parameter(Mandatory=$true, ParameterSetName="set1", position=0)] [ValidateNotNullOrEmpty()] [String] $Username, [Parameter...
PowerShellCorpus/PoshCode/POC csharp expressions_2.ps1
POC csharp expressions_2.ps1
function run-csharpexpression([string] $expression ) { $global:ccounter = [int]$ccounter + 1 $local:name = [system.guid]::NewGuid().tostring().replace('-','_').insert(0,"csharpexpr") $local:ns = "ShellTools.DynamicCSharpExpression.N${ccounter}" $local:template = @" using System; using System.IO; using Syste...
PowerShellCorpus/PoshCode/Add _ Get-Help -Full_1.ps1
Add _ Get-Help -Full_1.ps1
$executionContext.SessionState.InvokeCommand.PreCommandLookupAction = { param($CommandName, $CommandLookupEventArgs) if($CommandName.StartsWith("?")) { $RealCommandName = $CommandName.TrimStart("?") $CommandLookupEventArgs.CommandScriptBlock = { Get-Help $RealCommandName -Full...
PowerShellCorpus/PoshCode/Send-Growl _1.1.ps1
Send-Growl _1.1.ps1
## This is the first version of a Growl module (just dot-source to use in PowerShell 1.0) ## v 1.0 supports a very simple notice, and no callbacks ## v 2.0 supports registering multiple message types ## supports callbacks ## v 2.1 redesigned to be a module used from apps, rather than it's own "PowerGrowler" a...
PowerShellCorpus/PoshCode/Get-ADGroupModifications.ps1
Get-ADGroupModifications.ps1
###########################################################################" # # NAME: Get-ADGroupModificationsReport.ps1 # # AUTHOR: Jan Egil Ring # EMAIL: jan.egil.ring@powershell.no # # COMMENT: Generates a HTML-report of Active Directory group membership modifications (addings and deletions). # Sp...
PowerShellCorpus/PoshCode/Find-Command.ps1
Find-Command.ps1
function Find-Command{ param([Parameter($Mandatory=$true)]$question) Get-Command -Verb ($question.Split() | Where {Get-Verb $_ }) -Noun $question.Split() }
PowerShellCorpus/PoshCode/Import-Delimited 2.3.ps1
Import-Delimited 2.3.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/Delete-LocalAccount.ps1
Delete-LocalAccount.ps1
<# .SYNOPSIS A script that removes a local user account .DESCRIPTION This script searches ActiveDirectory for computer accounts, for each computer account it removes the specified user account. .PARAMETER ADSPath The ActiveDirectory namespace to search for computers ...
PowerShellCorpus/PoshCode/Import-NmapXML_1.ps1
Import-NmapXML_1.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/Get-UcsServerVlan_1.ps1
Get-UcsServerVlan_1.ps1
function Get-UcsServerVlan { Get-UcsServiceProfile | Foreach-Object { $sp = $_ $sp | Get-UcsVnic | Foreach-Object { $vn = $_ $vn | Get-UcsVnicInterface | Foreach-Object { $output = New-Object psobject –property @{ Server = $sp.Name ...
PowerShellCorpus/PoshCode/IsoDates.psm1.ps1
IsoDates.psm1.ps1
#requires -version 1.0 # or version 2.0, obviously ## ISO 8601 Dates ######################################################################## ## Copyright (c) Joel Bennett, 2009 ## Free for use under GPL, MS-RL, MS-PL, or BSD license. Your choice. function Get-ISODate { #.Synopsis # Get the components of an IS...
PowerShellCorpus/PoshCode/Set-LocalPassword_1.ps1
Set-LocalPassword_1.ps1
param( [switch]$Help , [string] $User , [string] $Password , [string[]] $ComputerNames = @() ) $usage = @' Get-OUComputerNames usage : [computerName1,computerName2,... | ] ./Set-LocalPassword.ps1 [-user] <userName> [-password] <password> [[-computers] computerName1,computerName2,...] returns : Sets lo...
PowerShellCorpus/PoshCode/EnvStacks Module 1.0.ps1
EnvStacks Module 1.0.ps1
## EnvStacks.psm1 module ## NOTE: If you "download" this, make sure it's a psm1 extension before you Add-Module ## NOTE: this will work as a regular v1.0 script if you dot-source it, but it *will* pollute your variable space a bit ## you'll need to comment out the Export-ModuleMember line at the bottom ... ##...
PowerShellCorpus/PoshCode/Set-Computername_6.ps1
Set-Computername_6.ps1
function Set-ComputerName { param( [switch]$help, [string]$originalPCName=$(read-host "Please specify the current name of the computer"), [string]$computerName=$(read-host "Please specify the new name of the computer")) $usage = "set-ComputerName -originalPCname CurrentName -computername AnewName" if (...
PowerShellCorpus/PoshCode/Get-FileEncoding.ps1
Get-FileEncoding.ps1
<# .SYNOPSIS Gets file encoding. .DESCRIPTION The Get-FileEncoding function determines encoding by looking at Byte Order Mark (BOM). Based on port of C# code from http://www.west-wind.com/Weblog/posts/197245.aspx .EXAMPLE Get-ChildItem *.ps1 | select FullName, @{n='Encoding';e={Get-FileEncoding $_.FullName}} | ...
PowerShellCorpus/PoshCode/SharePoint build script_2.ps1
SharePoint build script_2.ps1
@@#BASEPATH variable should be explicitly set in every @@#build script. It represents the "root" @@#of the project folder, underneath which all tools, source, config settings, @@#and deployment folder lie. @@$global:basepath = (resolve-path ..).path @@function Set-BasePath([string]$path) @@{ @@ $global:basepath...
PowerShellCorpus/PoshCode/Get-ExpiredCert.ps1
Get-ExpiredCert.ps1
Function Get-ExpiredCert { <# .SYNOPSIS Reports the number of expired certificates published to a user account in Active Directory. .DESCRIPTION This will give you a total count of expired certs for each user account. .PARAMETER InputObject Specifies the user object. This would be one or more Di...
PowerShellCorpus/PoshCode/Show-ADGroupMembership.ps1
Show-ADGroupMembership.ps1
# Author: Steven Murawski http://www.mindofroot.com # This script requires the Show-NetMap script from Doug Finke and the NetMap files # These can be found at http://dougfinke.com/blog/?p=465 # # Also required are the Quest AD Cmdlets. #requires -pssnapin Quest.ActiveRoles.ADManagement param([string]$Search...
PowerShellCorpus/PoshCode/Server Inventory.ps1
Server Inventory.ps1
#This script requires: #Windows Powershell 1.0 = http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx #PowerGui = http://www.powergui.org/downloads.jspa #Quest ActiveRoles Management Shell for Active Directory = http://www.quest.com/powershell/activeroles-server.aspx #VMware I...
PowerShellCorpus/PoshCode/Logger.psm1 0.6.ps1
Logger.psm1 0.6.ps1
<# Name : Universal NLog Logging Module (NLog.psm1) Version : 0.6 2010-05-17 Author : Joel Bennett (MVP) Site : http://www.HuddledMasses.org/ Version History: 0.6 - Removed a few references to Log4Net that had been left behind (oops). 0.5 - Port to NLog from Log4Net ( http:...
PowerShellCorpus/PoshCode/Invoke-SqlCmd2.ps1
Invoke-SqlCmd2.ps1
function Invoke-Sqlcmd2 { param( [string]$ServerInstance, [string]$Database, [string]$Query, [Int32]$QueryTimeout=30 ) $conn=new-object System.Data.SqlClient.SQLConnection $conn.ConnectionString="Server={0};Database={1};Integrated Security=True" -f $ServerInstance,$Database ...
PowerShellCorpus/PoshCode/Findup_27.ps1
Findup_27.ps1
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Security.Cryptography; using System.Runtime.InteropServices; using Microsoft.Win32; using System.IO; using System.Text.RegularExpressions; namespace Findup { public class FileLengthComparer : I...
PowerShellCorpus/PoshCode/replace-regexgroup.ps1
replace-regexgroup.ps1
#region @3 ## Function to do a regex replace of all matches with an expression per match that has local variables ##created automatically for the named groups so that you can use those varibles in your expression function replace-regexgroup ([regex]$regex, [string]$text ,[scriptblock] $replaceexpression) { $regex....
PowerShellCorpus/PoshCode/8014f3e2-68e3-4145-bd77-badc10360e30.ps1
8014f3e2-68e3-4145-bd77-badc10360e30.ps1
param([Parameter(Mandatory=$true)][string]$Path,[Parameter(Mandatory=$true)][string]$Destination) Get-ChildItem -Path $Path | Where-Object { !$_.PSIsContainer } | foreach { $Target = Join-Path -Path $Destination -ChildPath (Split-Path -Leaf $_) if ( Test-Path -Path $Target -PathType Leaf ) { Rename-Item -Path...
PowerShellCorpus/PoshCode/Create SP2010 Farm V03.ps1
Create SP2010 Farm V03.ps1
############################################################################ ## Create-SPFarm ## V 0.3 ## Jos.Verlinde ############################################################################ Param ( [String] $Farm = "SP2010", [String] $SQLServer = $env:COMPUTERNAME, [String] $Passphrase = "pass@word1"...
PowerShellCorpus/PoshCode/CertMgmt pack.ps1
CertMgmt pack.ps1
##################################################################### # CertMgmtPack.ps1 # Version 0.51 # # Digital certificate management pack # # Vadims Podans (c) 2009 # http://www.sysadmins.lv/ ##################################################################### #requires -Version 2.0 function Import-C...
PowerShellCorpus/PoshCode/egg_timer_2.ps1
egg_timer_2.ps1
function GenerateForm { [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null $form_main = New-Object System.Windows.Forms.Form $reset_button = New-Object System.Windows.Forms.Button $label1 = New-Object Sys...
PowerShellCorpus/PoshCode/h20 -Hashtables 2 object_2.ps1
h20 -Hashtables 2 object_2.ps1
#hashtable to object function. #used to be able to make custom objects with math inside the pipeline #e.g. 1..10 | h20 { @{karl = $_;dude = $_+1} } #gps | h20 { @{name = $_.processname; mem = $_.workingset / 1MB} } function h20([scriptblock]$sb ) { begin {} process{ if ($sb -ne $null) { ...
PowerShellCorpus/PoshCode/Get-NaVolumeLatency.ps1
Get-NaVolumeLatency.ps1
<# .SYNOPSIS Get the different protocol latencies for a specified volume. .DESCRIPTION Get the different protocol latencies for a specified volume. .PARAMETER Volume Volume to retrieve the latency. .PARAMETER Protocol Protocol to collect latency for valid values are 'all','nfs','cifs','san','fcp...
PowerShellCorpus/PoshCode/Manage ASP_4.NET Providers.ps1
Manage ASP_4.NET Providers.ps1
# Manage_ASP_NET_Providers.ps1 # by Chistian Glessner # http://iLoveSharePoint.com # have to be initialized. 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(...
PowerShellCorpus/PoshCode/Invoke-ExecuteTSQL _1.ps1
Invoke-ExecuteTSQL _1.ps1
####################### <# .SYNOPSIS Execute T-SQL Statments and return messages from SQL Server (print). .DESCRIPTION Execute T-SQL Statments and return messages from SQL Server (print). .INPUTS None You cannot pipe objects to Invoke-ExecuteTSQL .OUTPUTS PSObject : Boolean Exitcode = $True or $False in...
PowerShellCorpus/PoshCode/Get-SiSReport.ps1
Get-SiSReport.ps1
Function New-LocalUser { <# .SYNOPSIS Create a new user account on the local computer. .DESCRIPTION This function will create a user account on the local computer. .PARAMETER Computer The NetBIOS name of the computer that you will create the account on. .PARAMETER User The user ...
PowerShellCorpus/PoshCode/Remove-XmlNamespace.ps1
Remove-XmlNamespace.ps1
function Remove-XmlNamespace { #.Synopsis # Removes namespace definitions and prefixes from xml documents #.Description # Runs an xml document through an XSL Transformation to remove namespaces from it if they exist. # Entities are also naturally expanded #.Parameter Content # Specifies a string that contain...
PowerShellCorpus/PoshCode/28fbc2a5-866d-4bb2-8d93-78099b503621.ps1
28fbc2a5-866d-4bb2-8d93-78099b503621.ps1
function cpu-usage { if ($Args) {$machine=$Args} else {$machine="localhost"} #loop to refresh information cpu usage while($auxiliary -ne 'Q') { #first sample of processes $before = gwmi win32_perfrawdata_perfproc_process -ComputerName $machine sleep -Millis...
PowerShellCorpus/PoshCode/FuncionInfo.types.ps1xml.ps1
FuncionInfo.types.ps1xml.ps1
<?xml version="1.0" encoding="utf-8" ?> <Types> <Type> <Name>System.Management.Automation.FunctionInfo</Name> <Members> <ScriptProperty> <Name>Verb</Name> <GetScriptBlock> if ($this.Name.Contains("-")) { $this.Name.Substring(0,$this.Name.Indexof("-")) } else { $null ...
PowerShellCorpus/PoshCode/New-BootsGadget.ps1
New-BootsGadget.ps1
New-BootsGadget { #.Synopsis # Create desktop gadgets with no window chrome #.Description # Provides a wrapper for generating gadget windows with PowerBoots. It adds two parameters to the usual New-PowerBoots command: RefreshRate and On_Refresh. # # Gadget windows are created with AllowsTransparency, Back...
PowerShellCorpus/PoshCode/Get Twitter RSS Feed_3.ps1
Get Twitter RSS Feed_3.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/Inventory_1.ps1
Inventory_1.ps1
############################################################################ # # Collect.ps1 # Version: 0.2 # Script to Collect Information from PCs in a Subnet # By: Brad Blaylock # For: St. Bernards RMC # Date: 3-25-2010 # ############################################################################ #...
PowerShellCorpus/PoshCode/Tac (reverse cat).ps1
Tac (reverse cat).ps1
param([string]$path) Set-PSDebug -Strict $fs = New-Object System.IO.FileStream ((Resolve-Path $path), 'Open', 'Read') trap { $fs.Close(); break } $pos = $fs.Length $sb = New-Object System.Text.StringBuilder while (--$pos -ge 0) { [void]$fs.Seek($pos, 'Begin') $ch = [char]$fs.ReadByte() if ($ch ...
PowerShellCorpus/PoshCode/Execute-SQLCommand_3.ps1
Execute-SQLCommand_3.ps1
function Execute-SQLCommand {param( [string]$Server, #the host name of the SQL server [string]$Database, #the name of the database [System.Data.SqlClient.SqlCommand]$Command) #the command to execute (name of stored procedure) $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlCo...
PowerShellCorpus/PoshCode/h20 -Hashtables 2 object_1.ps1
h20 -Hashtables 2 object_1.ps1
#hashtable to object function. #used to be able to make custom objects with math inside the pipeline #e.g. 1..10 | h20 { @{karl = $_;dude = $_+1} } #gps | h20 { @{name = $_.processname; mem = $_.workingset / 1MB} } function h20([scriptblock]$sb ) { begin {} process{ if ($sb -ne $null) { ...
PowerShellCorpus/PoshCode/Get-Sysinternals_1.ps1
Get-Sysinternals_1.ps1
function Get-SysInternals { param ( $sysIntDir=(join-path $env:systemroot "\\Sysinternals\\") ) if(!(Test-Path -Path $sysIntDir -PathType Container)) { $null = New-Item -Type Directory -Path $sysIntDir -Force } $log = join-path $sysIntDir "changes.log" Add-Content ...
PowerShellCorpus/PoshCode/Hash Checker_3.ps1
Hash Checker_3.ps1
#.Synopsis # Test the HMAC hash(es) of a file #.Description # Takes the HMAC hash of a file using specified algorithm, and optionally, compare it to a baseline hash #.Example # Test-Hash npp.5.3.1.Installer.exe -HashFile npp.5.3.1.release.md5 # # Searches the provided hash file for a line matching the "...
PowerShellCorpus/PoshCode/TabExpansion_4.ps1
TabExpansion_4.ps1
## Tab-Completion ################# ## 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<tab> ## $a = New-Object "Int32[,]" 2,3; $b = "PowerShell","PowerShe...
PowerShellCorpus/PoshCode/Reset Time Sync Setting_1.ps1
Reset Time Sync Setting_1.ps1
######################################################## # Created by Brian English # Brian.English@charlottefl.com # eddiephoenix@gmail.com # # for Charlotte County Government # No warranty suggested or implied ######################################################## # Purpose: Cycle through all VMs on a...
PowerShellCorpus/PoshCode/Add-SqlTable_3.ps1
Add-SqlTable_3.ps1
try {add-type -AssemblyName "Microsoft.SqlServer.ConnectionInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" -EA Stop} catch {add-type -AssemblyName "Microsoft.SqlServer.ConnectionInfo"} try {add-type -AssemblyName "Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8...
PowerShellCorpus/PoshCode/finddupe_23.ps1
finddupe_23.ps1
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 try { $stream = $file.OpenRead() } ...
PowerShellCorpus/PoshCode/Computer Inventory_1.ps1
Computer Inventory_1.ps1
# ======================================================== # # Script Information # # Title: Remote Computer Inventory # Author: Assaf Miron # Originally created: 21/06/2008 # Original path: Computer-Inventory.PS1 # Description: Collects Remote Computer Data Using WMI and Registry Access # Outputs...
PowerShellCorpus/PoshCode/Get-OpenLDAP.ps1
Get-OpenLDAP.ps1
Param($user, $password = $(Read-Host "Enter Password" -asSec), $filter = "(objectclass=user)", $server = $(throw '$server is required'), $path = $(throw '$path is required'), [switch]$all, [switch]$verbose) function GetSecurePass ($SecurePassword) { $Ptr = [System.Run...
PowerShellCorpus/PoshCode/coolprompt.ps1
coolprompt.ps1
$global:wmilocalcomputer = get-WMIObject -class Win32_OperatingSystem -computer "." $global:lastboottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($wmilocalcomputer.lastbootuptime) $global:originaltitle = [console]::title function prompt { $up=$(get-date)-$lastboottime $upstr="$([dat...
PowerShellCorpus/PoshCode/d5ae4c48-9aa7-424e-9d74-61c687175d1b.ps1
d5ae4c48-9aa7-424e-9d74-61c687175d1b.ps1
get-vc virtualCenterServerName get-vmhost | Get-VirtualSwitch -Name SwitchName | New-VirtualPortGroup -Name VLAN_12 -VLANID 12
PowerShellCorpus/PoshCode/Set-SecureAutoLogon.ps1
Set-SecureAutoLogon.ps1
[cmdletbinding()] param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] $Username, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [System.Security.SecureString] $Password, [Parameter()] [string] $Domain, [Parameter()] [Int] $AutoLogonCount, [Parameter()] [switch...
PowerShellCorpus/PoshCode/Get-FileTail 1.0.ps1
Get-FileTail 1.0.ps1
#.Synopsis # Show the last n lines of a text file #.Description # This is just a tail script for PowerShell, using seekable streams to avoid reading the whole file and using v2 eventing to detect changes and provide a -Continuous mode. #.Parameter Name # The file name to tail #.Parameter Lines # The number ...
PowerShellCorpus/PoshCode/Get-FSMORoleOwner_1.ps1
Get-FSMORoleOwner_1.ps1
Function Get-FSMORoleOwner { <# .SYNOPSIS Retrieves the list of FSMO role owners of a forest and domain .DESCRIPTION Retrieves the list of FSMO role owners of a forest and domain .NOTES Name: Get-FSMORoleOwner Author: Boe Prox DateCreated: 06/9/2011 .EXAMPLE ...