full_path
stringlengths
31
232
filename
stringlengths
4
167
content
stringlengths
0
48.3M
PowerShellCorpus/PoshCode/Import-Certificate_5.ps1
Import-Certificate_5.ps1
#requires -Version 2.0 function Import-Certificate { param ( [IO.FileInfo] $CertFile = $(throw "Paramerter -CertFile [System.IO.FileInfo] is required."), [string[]] $StoreNames = $(throw "Paramerter -StoreNames [System.String] is required."), [switch] $LocalMachine, [switch] $CurrentUser, [string...
PowerShellCorpus/PoshCode/New-DFSRHealthReport.ps1
New-DFSRHealthReport.ps1
<# NAME: New-DFSRHealthReport.ps1 AUTHOR: Jan Egil Ring EMAIL: jan.egil.ring@powershell.no COMMENT: Script to generate a new DFS-R HTML Health Report for the Domain System Volume (SYSVOL) replication group using the native dfsradmin.exe tool. More information: You have a royalty-free right...
PowerShellCorpus/PoshCode/Out-Voice 2.0.ps1
Out-Voice 2.0.ps1
# --------------------------------------------------------------------------- ## <Script> ## <Author> ## Joel "Jaykul" Bennett ## </Author> ## <Description> ## Outputs text as spoken words ## </Description> ## <Usage> ## Out-Speech "Hello World" ## </Usage> ## <Version>2.0</Version> ## </Script> # --------...
PowerShellCorpus/PoshCode/INICIAR-RDP.ps1
INICIAR-RDP.ps1
######################################################################################################################## # NAME # Start-RDP # # SYNOPSIS # Opens a remote desktop connection to another computer. # # SYNTAX # Start-RDP [[-Server] <string>] [[-Width] <int>] [[-Height] <int>] # Star...
PowerShellCorpus/PoshCode/get windows product key_3.ps1
get windows product key_3.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/Office 365 - get email .ps1
Office 365 - get email .ps1
$Content = '$script:showWindowAsync = Add-Type –memberDefinition @”','[DllImport("user32.dll")]','public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);','“@ -name “Win32ShowWindowAsync” -namespace Win32Functions –passThru','function Show-PowerShell() {','$null = $showWindowAsync::ShowWindowAsync((Get-Pr...
PowerShellCorpus/PoshCode/Compare-DellUpdates_1.ps1
Compare-DellUpdates_1.ps1
#Requires -version 2 #Author: Nathan Linley #Script: Computer-DellUpdates #Site: http://myitpath.blogspot.com #Date: 2/9/2012 param( [parameter(mandatory=$true)][ValidateScript({test-path $_ -pathtype 'leaf'})][string]$catalogpath, [parameter(mandatory=$true,ValueFromPipeline=$true)][string]$server ) fun...
PowerShellCorpus/PoshCode/Get-Parameter_16.ps1
Get-Parameter_16.ps1
function Get-Parameter { [OutputType('System.String')] [CmdletBinding()] param( [Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)] [ValidateNotNullOrEmpty()] [String]$Command, [Parameter(Position=1)] [String[]]$Name=@('*'), [Parameter()] [Validate...
PowerShellCorpus/PoshCode/Reflection Module 4.0.ps1
Reflection Module 4.0.ps1
#requires -version 2.0 # ALSO REQUIRES Autoload for some functionality # You should create a Reflection.psd1 with the contents: @{ RequiredModules = @("Autoload"); GUID="64b5f609-970f-4e65-b02f-93ccf3e60cbb"; ModuleVersion="3.5.0.0" } #History: # 1.0 - First public release (March 19, 2010) # 2.0 - Private Build ...
PowerShellCorpus/PoshCode/Format-HexString.ps1
Format-HexString.ps1
## Format-HexString.ps1 ## Format a byte array as a hexadecimal string ## ## Example usage: ## get-content 'c:\\windows\\Coffee Bean.bmp' -encoding byte | Format-HexString | more ## Convert the input to an array of bytes. This is a strongly-typed variable, ## so that we're not trying to iterate over strings, d...
PowerShellCorpus/PoshCode/netcast show downloader.ps1
netcast show downloader.ps1
cd M:\\Files\\Netcasts\\ShowName # switch to the diretory to store your content Import-Module BitsTransfer # enable BITS on host machine as a file transfer method $start=47 # start epidode number $end=170 # end epidode number $url="http://download.domain.com/episodes/" # URL of the download up to the ...
PowerShellCorpus/PoshCode/New-XML.ps1
New-XML.ps1
### A first stab at the worlds simplest DSL: ### How to generate XML from PowerShell, in code instead of string-substitution $xlr8r = [type]::gettype("System.Management.Automation.TypeAccelerators") $xlinq = [Reflection.Assembly]::Load("System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c56...
PowerShellCorpus/PoshCode/PowerShell Template_1.ps1
PowerShell Template_1.ps1
Function New-Script { $strName = $env:username $date = get-date -format d $name = Read-Host "Filename" if ($name -eq "") { $name="NewTemplate" } $email = Read-Host "eMail Address" if ($email -eq "") { $email="youremail@yourhost.com" } $file = New-Item -type file "$name.ps1" -force $template=@" ###############...
PowerShellCorpus/PoshCode/Product key_2.ps1
Product key_2.ps1
from System import Array, Char, Console from System.Collections import ArrayList from Microsoft.Win32 import Registry def DecodeProductKey(digitalProductID): map = ("BCDFGHJKMPQRTVWXY2346789").ToCharArray() key = Array.CreateInstance(Char, 29) raw = ArrayList() i = 52 while i < 67: raw...
PowerShellCorpus/PoshCode/vibackup-lx.ps1
vibackup-lx.ps1
Param ( $viServer, $bakVM, $lxDest ) #region check if (!$viServer) { $viServer = Read-Host -Prompt "VI Server " } if (!$bakVM) { $bakVM = Read-Host -Prompt "VM to Backup " } if (!$lxDest) { $lxDest = Read-Host -Prompt "Backup Path (ex. /srv/backup) " } #endregion #region globalvars $encoding = "OEM" ...
PowerShellCorpus/PoshCode/Find-AmazonBook.ps1
Find-AmazonBook.ps1
## Requires HttpRest http://poshcode.org/691 ## Add-Module HttpRest ##Or:## . HttpRest.ps1 ## YOU MUST Provide an Amazon Web Services key (AWSKey) and a $Book title #################################################################################################### Set-HttpDefaultUrl "http://ecs.amazonaws.com/onca/...
PowerShellCorpus/PoshCode/Findup_17.ps1
Findup_17.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/Import-ExcelToSQL_1.ps1
Import-ExcelToSQL_1.ps1
#Change these settings as needed $filepath = 'C:\\Users\\u00\\Documents\\backupset.xlsx' #Comment/Uncomment connection string based on version #Connection String for Excel 2007: $connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`"$filepath`";Extended Properties=`"Excel 12.0 Xml;HDR=YES`";" #Connection S...
PowerShellCorpus/PoshCode/New-Eicar.ps1
New-Eicar.ps1
function New-Eicar { <# .SYNOPSIS New-Eicar Author: Chris Campbell (@obscuresec) License: BSD 3-Clause .DESCRIPTION A function that generates the EICAR string to test ondemand scanning of antivirus products. .PARAMETER $Path Specifies the path to write the eicar file...
PowerShellCorpus/PoshCode/Get-Films (From Netflix).ps1
Get-Films (From Netflix).ps1
function Get-Films { param($Name) $proxy = New-ODataServiceProxy http://odata.netflix.com/Catalog/ if($Name -match "\\*") { $sName = $Name -replace "\\*" $Global:Films = $proxy.Titles.AddQueryOption('$filter',"substringof('$sName',Name)") | Where { $_.Name -like $Name } } else { $Glob...
PowerShellCorpus/PoshCode/Reverse filename sequenc_5.ps1
Reverse filename sequenc_5.ps1
# Reverse filename sequence v 0.9 # Author: Sean Wendt # # This script will rename a sequenced set of files in a directory. # For example, you have foobar01.jpg, foobar02.jpg, foobar03.jpg # -- it will reverse the order, so the last file is now 01, the second to last 02, etc.. # # Limitations: -You cannot us...
PowerShellCorpus/PoshCode/ISE-Lines_1.ps1
ISE-Lines_1.ps1
#requires -version 2.0 ## ISE-Lines module v 1.1 ## DEVELOPED FOR CTP3 ## See comments for each function for changes ... ############################################################################################################## ## Provides Line cmdlets for working with ISE ## Duplicate-Line - Duplicates curr...
PowerShellCorpus/PoshCode/Custom Accelerators.ps1
Custom Accelerators.ps1
#requires -version 2.0 ## Custom Accelerators for PowerShell 2 #################################################################################################### ## A script module for PowerShell 2 which allows the user to create their own custom type accelerators. ## Thanks to "Oisin Grehan for the discovery":h...
PowerShellCorpus/PoshCode/Add _ Get-Help -Full.ps1
Add _ Get-Help -Full.ps1
$executionContext.SessionState.InvokeCommand.PreCommandLookupAction = { param($CommandName, $CommandLookupEventArgs) if($CommandName.StartsWith("?")) { $RealCommandName = $CommandName.TrimStart("?") $CommandLookupEventArgs.CommandScriptBlock = { Get-Help $RealCommandName -Full...
PowerShellCorpus/PoshCode/Convert-PowerPack2Ps1.ps1
Convert-PowerPack2Ps1.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/SQLParser.ps1
SQLParser.ps1
#requires -version 2 #Uses Visual Studio Database Edition classes Microsoft.Data.Schema.ScriptDom and Microsoft.Data.Schema.Script.Sql to parse T-SQL #Chad Miller #http://chadwickmiller.spaces.live.com/ $PSScriptRoot = (Split-Path $MyInvocation.MyCommand.Path -Parent) Add-Type -Path "$PSScriptRoot\\Microso...
PowerShellCorpus/PoshCode/01fef1f2-03fd-4b4d-bed8-aa3c4999fedc.ps1
01fef1f2-03fd-4b4d-bed8-aa3c4999fedc.ps1
Connect-VIServer <vCenter server> # Uncomment the next line to test this script # $WhatIfPreference = $true if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { Add-PSSnapin VMware.VimAutomation.Core } if (-not (Get-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContin...
PowerShellCorpus/PoshCode/VM Performance Report_1.ps1
VM Performance Report_1.ps1
<# .SYNOPSIS The script creates an HTML report for given vSphere VM's, that contains VM performance data over a given period. The script then emails the report to a given address. .DESCRIPTION The script requires an input file, supplied as an argument to the script. The first line of this file contains an e...
PowerShellCorpus/PoshCode/ISEFun_1.psm1.ps1
ISEFun_1.psm1.ps1
# Module version 0.2 # Author: Bartek Bielawski (@bielawb on twitter) # Purpose: Add functionality to PowerShell ISE # Description: Adds Add-ons menu 'ISEFun' with all functions included. # User can add any action there using Add-MyMenuItem function # One of functions (Copy item from history) was build using...
PowerShellCorpus/PoshCode/Start-ComputerJobs_2.ps1
Start-ComputerJobs_2.ps1
#requires -version 2.0 function Start-ComputerJobs{ <# .NOTES Name: Start-ComputerJobs Author: Tome Tanasovski Created: 6/25/2010 Modified: 6/25/2010 Version: 1.2 Website: http://powertoe.wordpress.com .SYNOPSIS Multithreads a scriptblock with jobs ...
PowerShellCorpus/PoshCode/archive.ps1
archive.ps1
$rootDir = 'C:\\Documents and Settings\\buddyl\\My Documents\\Powershell Scripts\\'; $temp = $rootDir + 'temp' mkdir $temp $tempDir = $temp + '\\' $targetFolder1 = $rootDir + 'test' $zip1 = $tempDir + 'test1.zip' gi $targetFolder1 | out-zip $zip1 $_ $targetFolder2 = $rootDir + 'test2' $zip2 = $tempDir + '...
PowerShellCorpus/PoshCode/Get-QADGroupNesting_1.ps1
Get-QADGroupNesting_1.ps1
Param ( [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, HelpMessage="DN or ObjectGUID of the AD Group." )] [string]$groupIdentity, [switch]$showTree ) #Validate Quest PSSnapin is loaded Add-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction ...
PowerShellCorpus/PoshCode/Remove local profiles.ps1
Remove local profiles.ps1
<# .SYNOPSIS This is a powershell script form to remove a users local profile from a workstation and and gives the option to remove the users profile fromt he network. .DESCRIPTION This script askes for a machine name. It displays all of the roaming profiles on that machine. The administrator sele...
PowerShellCorpus/PoshCode/Set-FileWriteable.ps1
Set-FileWriteable.ps1
function Set-FileWriteable { #.Example # $s = New-PSSession $ComputerName # C:\\PS>$files = Invoke-Command $s { ls } # .... # C:\\PS>Set-FileWriteable $files # param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)] $File , [switch]$Passthru ) process { foreach($path in @($file)) { ...
PowerShellCorpus/PoshCode/DirToday Extended.ps1
DirToday Extended.ps1
## NAME: Get-Dirty.ps1 ## AUTHOR: Barry Morrison ## LASTEDIT: 07/05/2011 16:18:33 <# .Synopsis Get's files from today's date. Will also return narrowed results based on keyword .Description Get's files from today's date. Will also return narrowed results based on keyword .Parameter...
PowerShellCorpus/PoshCode/Get-ADGroupMembers_5.ps1
Get-ADGroupMembers_5.ps1
Function Get-ADGroupMembers { <# .SYNOPSIS Return a collection of users in an ActiveDirectory group. .DESCRIPTION This function returns an object that contains all the properties of a user object. This function works for small groups as well as groups in ex...
PowerShellCorpus/PoshCode/get-kbinfo.ps1
get-kbinfo.ps1
# -==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # Author: Kris Cieslak (defaultset.blogspot.com) # Date: 2010-05-26 # Description: Identifying knowledge base article by id number taken from # string or filename. # # Parameters: filename / kno...
PowerShellCorpus/PoshCode/ServicePWChgReset.ps1
ServicePWChgReset.ps1
# ============================================================================================== # # NAME: ServicePWChgReset.ps1 # # AUTHOR: Saehrig, Steven # DATE : 8/26/2008 # @@# COMMENT: Please read comments on each section! # 1st - Search Domain computers for matching name and import into array. # ...
PowerShellCorpus/PoshCode/chkhash_30.ps1
chkhash_30.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/Test-Prompt_3.ps1
Test-Prompt_3.ps1
$choices = [System.Management.Automation.Host.ChoiceDescription[]]( (New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Choose me!"), (New-Object System.Management.Automation.Host.ChoiceDescription "&No","Pick me!")) $Answer = $host.ui.PromptForChoice('Caption',"Message",$choices,(1)) Write-...
PowerShellCorpus/PoshCode/push-module function .ps1
push-module function .ps1
function Push-Module { param( [parameter(position=0, mandatory=$true)] [validatenotnullorempty()] [string]$ModuleName ) # find out what this module exports (and therefore what it overwrites) $metadata = new-module -ascustomobject { param([string]$ModuleName)...
PowerShellCorpus/PoshCode/Get-TranscriptFilePath.ps1
Get-TranscriptFilePath.ps1
#requires -version 2.0 function Get-TranscriptFilePath { try { $externalHost = $host.gettype().getproperty("ExternalHost", [reflection.bindingflags]"nonpublic,instance").getvalue($host, @()) $externalhost.gettype().getfield("transcriptFileName", "nonpublic,instance").getvalue($externalhos...
PowerShellCorpus/PoshCode/Get-FSMORoleOwner.ps1
Get-FSMORoleOwner.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 ...
PowerShellCorpus/PoshCode/Start-Timer.ps1
Start-Timer.ps1
## Start-Timer.ps1 ## A kitchen timer script with visible countdown and customizable audio alert and messages #################################################################################################### param( $seconds=0, $reason="The Timer", $SoundFile="$env:SystemRoot\\Media\\notify.wav", $minutes...
PowerShellCorpus/PoshCode/New-Zip_3.ps1
New-Zip_3.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/Write-Log_7.ps1
Write-Log_7.ps1
function Write-Log { #.Synopsis # Write to a rotating log file #.Example # Get-ChildItem C:\\ -Recurse | Select FullName, CreationTimeUtc, LastWriteTimeUtc | Write-Log Files.txt -Rotate 5mb # # Writes a file list to disc, breaking it into multiple files of approximately 5MB of data each [CmdletB...
PowerShellCorpus/PoshCode/Invoke-WindowsUpdate.ps1
Invoke-WindowsUpdate.ps1
###########################################################################" # # NAME: Invoke-WindowsUpdate.ps1 # # AUTHOR: Jan Egil Ring # EMAIL: jan.egil.ring@powershell.no # # COMMENT: Script to download and install updates from Windows Update/WSUS. Reporting and rebooting may be customized. # For m...
PowerShellCorpus/PoshCode/group-byobject_1.ps1
group-byobject_1.ps1
#groups by a set of properties, but returns then rather than as a string, as seperate properties on an object with _count , and _group for the original #ones returned from group object function group-byobject { [CmdletBinding()] param( [Parameter(ValueFromPipeline=$true,Mandatory=$true)] $InputObject , ...
PowerShellCorpus/PoshCode/SharpSsh 5.ps1
SharpSsh 5.ps1
#requires -version 2.0 ## A simple SSH Scripting module for PowerShell ## Retrieved from ## History: ## v1 - Initial Script ## v2 - Capture default prompt in New-SshSession ## v3 - Update to advanced functions, require 2.0, and add basic help ## v4(modification by Tao Klerks) - Update to reference modified Shar...
PowerShellCorpus/PoshCode/Help Differ 10000 v0.01.ps1
Help Differ 10000 v0.01.ps1
# These functions are meant to help generate a table that shows differences between # cmdlets among different versions of a module. # You will need a MoinMoin wiki to render the output. # If you don't have a MoinMoin wiki you might be able to use the sandbox at http://moinmo.in/WikiSandBox # Extracts some data fr...
PowerShellCorpus/PoshCode/get-DiskVolumeInfo.ps1
get-DiskVolumeInfo.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/New-XVM_5.ps1
New-XVM_5.ps1
#Examples <# New-XVM -Name "WS2012-TestServer01" -SwitchName "Switch(192.168.2.0/24)" -VhdType NoVHD New-XVM -Name "WS2012-TestServer02" -SwitchName "Switch(192.168.2.0/24)" -VhdType ExistingVHD -VhdPath 'D:\\vhds\\WS2012-TestServer02.vhdx' New-XVM -Name "WS2012-TestServer03" -SwitchName "Switch(192.168.2.0/24)" ...
PowerShellCorpus/PoshCode/134032f9-0687-4d0a-b267-6a42e5c116df.ps1
134032f9-0687-4d0a-b267-6a42e5c116df.ps1
#'*********************************************************************** #'* File: Check-Directory.ps1 #'* Creation Date: 2008/05/30 #'* Author: Jacob Hodges (Technology Effect) #'* Purpose: Checks to see if an INF File is already in the MDT Workbench. #'* Usage: .\\Create-DistributionShare.ps1 D:\\Dr...
PowerShellCorpus/PoshCode/GPRS Online log_1.ps1
GPRS Online log_1.ps1
################################################################################ # Get-GprsTime.ps1(V 1008) # Check the total connect time of any GPRS devices from a specified date. # Use the -Verbose switch for some extra information if desired. A default value # can be set with the -Monthly switch but can ...
PowerShellCorpus/PoshCode/Set-IPAddress_2.ps1
Set-IPAddress_2.ps1
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 subnet mask (ie 255.255.255.0)"), [string]$gateway = $(read-host "Enter...
PowerShellCorpus/PoshCode/ExceptionHandling.ps1
ExceptionHandling.ps1
## ExceptionHandling.ps1 ############################################################################################################## ## .Net style exception handling ############################################################################################################## ## Usage: ## . .\\ExceptionHandl...
PowerShellCorpus/PoshCode/802afd05-1132-4f41-9443-b27fbe20dfd8.ps1
802afd05-1132-4f41-9443-b27fbe20dfd8.ps1
function Get-Pecoff { <# .SYNOPSIS Takes file-name and outputs fileobject with two more properties poff_characteristic and poff_machinetype .DESCRIPTION This function creates file objects with PE properties for characteristic and machinetype .EXAMPLE For output from get-childitem or an...
PowerShellCorpus/PoshCode/AddTo-HostsFile.ps1
AddTo-HostsFile.ps1
function AddTo-HostsFile{ <# .DESCRIPTION This function checks to see if an entry exists in the hosts file. If it does not, it attempts to add it and verifies the entry. .EXAMPLE Networkign.AddTo-Hosts -IPAddress 192.168.0.1 -HostName MyMachine .EXTERNALHELP None. .FORWARDHELPTARGE...
PowerShellCorpus/PoshCode/Show-Sample_1.ps1
Show-Sample_1.ps1
if(!(Get-Command New-System.Windows.Input.CommandBinding -ErrorAction SilentlyContinue)) { Add-UIFunction -Type System.Windows.Input.CommandBinding } Show -Width 300 -Height 150 { DockPanel { Menu -DockPanel-Dock Top -Height 20 { MenuItem -Header "_File" { ## Hook up the "New" ...
PowerShellCorpus/PoshCode/New-CommandWrapper.ps1
New-CommandWrapper.ps1
##############################################################################\n##\n## New-CommandWrapper\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\nAdds ...
PowerShellCorpus/PoshCode/elevate-process (sudo)_1.ps1
elevate-process (sudo)_1.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/Xml Module 6.5.ps1
Xml Module 6.5.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/Write-DataTable_5.ps1
Write-DataTable_5.ps1
####################### <# .SYNOPSIS Writes data only to SQL Server tables. .DESCRIPTION Writes data only to SQL Server tables. However, the data source is not limited to SQL Server; any data source can be used, as long as the data can be loaded to a DataTable instance or read with a IDataReader instance. .INPUTS...
PowerShellCorpus/PoshCode/AsyncCallbacks in .NET.ps1
AsyncCallbacks in .NET.ps1
#requires -version 2.0 function New-ScriptBlockCallback { param( [parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [scriptblock]$Callback ) <# .SYNOPSIS Allows running ScriptBlocks via .NET async callbacks. .DESCRIPTION Allows running ScriptBl...
PowerShellCorpus/PoshCode/Get-HPAgentVersion.ps1
Get-HPAgentVersion.ps1
####################### <# .SYNOPSIS Gets HP PSP/SPP Agent Version .DESCRIPTION The Get-HPAgentVersion function gets the HP PSP/SPP version. .EXAMPLE Get-HPAgentVersion "Z002" This command gets information for computername Z002. .EXAMPLE Get-Content ./servers.txt | Get-HPAgentVersion This command gets inform...
PowerShellCorpus/PoshCode/Get-Constructor_1.ps1
Get-Constructor_1.ps1
function Get-Constructor { PARAM( [Type]$type ) $type.GetConstructors() | Format-Table @{ l="$($type.Name) Constructors" e={ ($_.GetParameters() | % { $_.ToString() }) -Join ", " } } } Set-Alias gctor Get-Constructor
PowerShellCorpus/PoshCode/Modify Excel.ps1
Modify Excel.ps1
# ----------------------------------------------------- function Release-Ref ($ref) { ([System.Runtime.InteropServices.Marshal]::ReleaseComObject( [System.__ComObject]$ref) -gt 0) [System.GC]::Collect() [System.GC]::WaitForPendingFinalizers() } # ----------------------------------------------------- ...
PowerShellCorpus/PoshCode/Download DefragTools _2.ps1
Download DefragTools _2.ps1
#requires -version 2.0 <# .Synopsis Downloads Channel 9 Defrag Tool Episode Video .DESCRIPTION Downloads Channel 9 Defrag Tool Episode Video in the format selected and to a given path. .EXAMPLE Downloads all shows in WMV format to the default Downloads Folder for the user. Get-DefragToolsShow -All...
PowerShellCorpus/PoshCode/Get-WordOutline.ps1
Get-WordOutline.ps1
function Get-WordOutline ( $Path, [int]$MaxDepth = 9 ) { if ( $Path -is [System.IO.FileInfo] ) { $Path = $_.FullName } $word = New-Object -comObject word.application $document = $wordd.documents.open( $path ) $outline = $document.paragraphs | Where-Object { $_.outlineLevel -le $MaxDepth } | ForEach-Object ...
PowerShellCorpus/PoshCode/chkhash_16.ps1
chkhash_16.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/Convert-BounceToX_1.ps1
Convert-BounceToX_1.ps1
# $Id: Convert-BounceToX500.ps1 610 2010-11-16 00:39:19Z jon $ # $Revision: 610 $ #.Synopsis # Convert Bounce to X500 #.Description # Convert URL Encoded address in a Bounce message to an X500 address # that can be added as an alias to the mail-enabled object #.Parameter bounceAddress # URL Encoded bounce...
PowerShellCorpus/PoshCode/VMware Daily Report_1.ps1
VMware Daily Report_1.ps1
# vCheck - Daily Error Report # # Changes: # Version 1.11 - Simplified mail function. # Version 1.10 - Added How many days old the snapshots are # Version 1.9 - Added ability to change user account which makes the WMI calls # Version 1.8 - Added Real name resolution via AD and sorted disk space by PerfFree # V...
PowerShellCorpus/PoshCode/HEX string to SID string_1.ps1
HEX string to SID string_1.ps1
Function EndianReverse ($strHex) { $intCounter=$strHex.length-1 do { $reverse=$reverse+$strHex.substring($intCounter-1, 2) $intCounter=$intCounter-2 } until ($intCounter -eq -1) return $reverse } Function hex2sid ($strHex) { $intSidVersionLength = 2 $intSubAuthorityCountLength = 2 $in...
PowerShellCorpus/PoshCode/MoveMailboxBySize.ps1
MoveMailboxBySize.ps1
### VARIABLES ### #Stop the script if an error ever occurs $ErrorActionPreference = "stop" #Base Directory $BaseDir="C:\\Scripts" #Place for Migration Reports $ReportFileDir="C:\\Scripts\\Logs" #Exclusion List of Mailboxes to Not Move. This should be a return-separated list of mailbox display names to av...
PowerShellCorpus/PoshCode/Get-PerformanceHistory 2.ps1
Get-PerformanceHistory 2.ps1
#requires -version 2.0 ## Get-PerformanceHistory.ps1 ############################################################################################################## ## Lets you see the amount of time recent commands in your history have taken ## History: ## v2 - adds a ton of parsing to make the output pretty ## ...
PowerShellCorpus/PoshCode/Get-ADGroupMembers_2.ps1
Get-ADGroupMembers_2.ps1
Function Get-ADGroupMembers { <# .SYNOPSIS Return a collection of users in an ActiveDirectory group. .DESCRIPTION This function returns an object that contains all the properties of a user object. This function works for small groups as well as groups in ex...
PowerShellCorpus/PoshCode/CSV Validator Framework.ps1
CSV Validator Framework.ps1
# --- begin test-csv.ps1 --- param( [string]$Path = $(throw "require CSV path!"), [string]$RulesetPath = $(throw "require Ruleset path!") ) $csvFiles = Resolve-Path -Path $Path # load rules if ((Test-Path (Resolve-Path $RulesetPath))) { # ruleset is found, execute and assign result to vari...
PowerShellCorpus/PoshCode/SMS_1.psm1.ps1
SMS_1.psm1.ps1
<# .Synopsis Functions for managing SMS and SCCM. .Notes NAME: SMS.psm1 AUTHOR: Tim Johnson <tojo2000@tojo2000.com> #> #Requires -version 2.0 [string]$default_wmi_provider_server = 'myserver' [string]$default_site = 'S00' function Get-SmsWmi { <# .Synopsis A function for accessing the...
PowerShellCorpus/PoshCode/RoboGUI.ps1
RoboGUI.ps1
# a helper GUI to create RoboCopy commands # uses FormsLib.ps1 # # /\\/\\o\\/\\/ # http://thePowerShellGuy.com # load windows.forms assembly and FormsLib.ps1 [system.reflection.assembly]::LoadWithPartialName('system.windows.forms') . .\\FormsLib.ps1 ###############################################...
PowerShellCorpus/PoshCode/BinaryClock V2.0.ps1
BinaryClock V2.0.ps1
Function Start-BinaryClock { <# .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. Key Input Tips: r: Toggles the resize mode of the clock so you can adjust the size....
PowerShellCorpus/PoshCode/Copy-MAGig.ps1
Copy-MAGig.ps1
function Copy-MAGig { param( [string]$src, [string]$dest, $exclude, [int]$width = 100, # used with the -log switch to format the log, [int]$ident = 2, # dito [switch]$log, # if -verbose had a nice format and its output cou...
PowerShellCorpus/PoshCode/Make a phone call_2.ps1
Make a phone call_2.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/Set-VMBuildCSVDeploy.ps1
Set-VMBuildCSVDeploy.ps1
####################################################################### # # Purpose: Build VMs from CSV file built by SET-VMBUILDCSV.ps1 # Author: David Chung # Docs: N/A # # v.1 - 02/10/2012 # # Instruction: ./set-vmbuildcsvdeploy.ps1 viserver csvfilename # #########################################...
PowerShellCorpus/PoshCode/PowerShell Template.ps1
PowerShell Template.ps1
Function New-Script { $strName = $env:username $date = get-date -format d $name = Read-Host "Filename" if ($name -eq "") { $name="NewTemplate" } $email = Read-Host "eMail Address" if ($email -eq "") { $email="youremail@yourhost.com" } $file = New-Item -type file "$name.ps1" -force $template=@" ###############...
PowerShellCorpus/PoshCode/Invoke-RemoteCommand.ps1
Invoke-RemoteCommand.ps1
<# # Script FileName: func_Invoke-RemoteCommand.ps1 # Current Version: A03 # Description: Run command on a remote computer as the currently logged on user. # Created By: Adam Listek # Version Notes # A01 - Initial Release # A02 - Conversion to Function # A03 - Abstracted to generic purpos...
PowerShellCorpus/PoshCode/Findup_15.ps1
Findup_15.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/Get-Hostname_2.ps1
Get-Hostname_2.ps1
# .SYNOPSIS # Print the hostname of the system. # .DESCRIPTION # This function prints the hostname of the system. You can additionally output the DNS # domain or the FQDN by using the parameters as described below. # .PARAMETER Short # (Default) Print only the computername, i.e. the same value as returned by $env...
PowerShellCorpus/PoshCode/group-byobject_4.ps1
group-byobject_4.ps1
function Group-ByObject { #.Synopsis # Groups by a set of properties, returning objects #.Description # A wrapper for the built-in Group-Object cmdlet which returns one of the original objects (with separate properties for each property used to group) rather than a simple string representation as the "name" of the ...
PowerShellCorpus/PoshCode/Disable-CopyPasta.ps1
Disable-CopyPasta.ps1
Begin { $disableCopy = "isolation.tools.copy.enable" $disableCopy_value = "false" $disablePaste = "isolation.tools.paste.enable" $disablePaste_value = "false" $disableGUI = "isolation.tools.setGUIOptions.enable" $disableGUI_vsalue = "false" } Process { #Make Sure it's a VM if ( $_ -isnot [VMwar...
PowerShellCorpus/PoshCode/Get-DCsFromDNS.ps1
Get-DCsFromDNS.ps1
function Get-DCsFromDNS($DomainName){ $DCs = get-dns _ldap._tcp.dc._msdcs.$DomainName -Type srv | select -ExpandProperty RecordsRR | %{$_.record.target} | select -Unique | sort | %{ get-dns $_ | select -ExpandProperty Answers | select Name,@{n='IPAddress';e={$_.Record}}} return $DCs }
PowerShellCorpus/PoshCode/Deploying VM with static_1.ps1
Deploying VM with static_1.ps1
# 1. Create a simple customizations spec $custSpec = New-OSCustomizationSpec -Type NonPersistent -OSType Windows -OrgName TestOrgName -FullName TestFullName -Workgroup TestWorkgroup # 2. Modify the default network customization settings $custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMod...
PowerShellCorpus/PoshCode/LibraryChart.ps1
LibraryChart.ps1
# --------------------------------------------------------------------------- ### <Script> ### <Author> ### Chad Miller ### </Author> ### <Description> ### Defines functions for wokring with Microsoft Chart Control for .NET 3.5 Framework ### Pipe output of Powershell command to Out-Chart function and specify c...
PowerShellCorpus/PoshCode/Xml Module 3.ps1
Xml Module 3.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. # IMPO...
PowerShellCorpus/PoshCode/NewUser in AD_OCS_Email.ps1
NewUser in AD_OCS_Email.ps1
# New User In PowerShell # ye110wbeard (EnergizedTech) Finally shuts up and writes a script that is USEFUL and doesn't sing about it # 7/15/2009 :) # And it couldn't have happened if it wasn't for the Powershell Community # # This script in many ways is VERY simple. I simply chose to use simple assignments i...
PowerShellCorpus/PoshCode/Colorize Subversion SVN_3.ps1
Colorize Subversion SVN_3.ps1
# draw output function drawlines($colors, $lines) { if (!$lines) { return } 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"="Ye...
PowerShellCorpus/PoshCode/VMWare Quick Migration_2.ps1
VMWare Quick Migration_2.ps1
######################################### #Name: VMWare Quick Migration Function #Author: Justin Grote <jgrote NOSPAMAT enpointe DOT com> #Credit: Inspired by Mike DiPetrillo's Quick Migration Script: http://www.mikedipetrillo.com/mikedvirtualization/2008/10/quick-migration-for-vmware-the-power-of-powershell.html #...
PowerShellCorpus/PoshCode/Get-RebootTime.ps1
Get-RebootTime.ps1
$compres = Read-Host -message "Enter a computer name." $date = Get-WmiObject Win32_OperatingSystem -ComputerName $compres | foreach{$_.LastBootUpTime} $RebootTime = [System.DateTime]::ParseExact($date.split('.')[0],'yyyyMMddHHmmss',$null) $RebootTime
PowerShellCorpus/PoshCode/Invoke-RickRoll.ps1
Invoke-RickRoll.ps1
function Invoke-RickRoll { <# .SYNOPSIS Invoke-RickRoll A RickRoll PowerShell Script :) Authors: Chris Campbell (@obscuresec) License: BSD 3-Clause .DESCRIPTION A script to call IE and send it to a URL. .PARAMETER VideoURL Specifies a URL to send IE to. .EXAMPLE ...
PowerShellCorpus/PoshCode/New-XVM_7.ps1
New-XVM_7.ps1
#Examples <# New-XVM -Name "WS2012-TestServer01" -SwitchName "Switch(192.168.2.0/24)" -VhdType NoVHD New-XVM -Name "WS2012-TestServer02" -SwitchName "Switch(192.168.2.0/24)" -VhdType ExistingVHD -VhdPath 'D:\\vhds\\WS2012-TestServer02.vhdx' New-XVM -Name "WS2012-TestServer03" -SwitchName "Switch(192.168.2.0/24)" ...
PowerShellCorpus/PoshCode/GPRS Online log_6.ps1
GPRS Online log_6.ps1
<# .SYNOPSIS Get-GprsTime (V4.0 Update for Windows 7 and allow time correction) Check the total connect time of any GPRS devices from a specified date. Use 'Get-Help .\\Get-GprsTime -full' to view Help for this script. .DESCRIPTION Display all the GPRS modem Event Log entries. While applications issued by the ...