full_path
stringlengths
31
232
filename
stringlengths
4
167
content
stringlengths
0
48.3M
PowerShellCorpus/PoshCode/Get-DelegateType.ps1
Get-DelegateType.ps1
Set-StrictMode -Version 2 function Get-DelegateType { <# .Synopsis Declares a non-generic delegate type for the method signature provided. .Description The Get-DelegateType function is the equivalent to declaring a delegate type in C# with the 'delegate' keyword. PowerShell has no such equivalent, hence this...
PowerShellCorpus/PoshCode/Resizer of pictures_3.ps1
Resizer of pictures_3.ps1
[reflection.assembly]::LoadWithPartialName("System.Drawing") $SizeLimit=1280 # required size of picture's long side $logfile="resizelog.txt" # log file for errors $toresize=$args[0] # list of directories to find and resize images. can be empty @@ if ([string]$toresize -eq &#8220;&#8221;) { # if ...
PowerShellCorpus/PoshCode/Blow up ESXi.ps1
Blow up ESXi.ps1
foreach ($i in 10..1) { Set-VMHostAdvancedConfiguration -name Annotations.WelcomeMessage -value "This host will self destruct in $i" } Start-Sleep 10 Set-VMHostAdvancedConfiguration -name Annotations.WelcomeMessage -value ""
PowerShellCorpus/PoshCode/Write-Log_4.ps1
Write-Log_4.ps1
function Write-Log { #region Parameters [cmdletbinding()] Param( [Parameter(ValueFromPipeline=$true,Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] $Message, [Parameter()] [ValidateSet(ōErrorö, ōWarnö, ōInfoö)] [string] $Level = ōInfoö, [Parameter()] [Switch] $NoConsole...
PowerShellCorpus/PoshCode/Get-PSExecutionPolicy.ps1
Get-PSExecutionPolicy.ps1
#Notes #1. x86 properites will be empty for x86 machines as this property only pertains x64 machines which have both x64 and x86 shells. #2. If policy registry key is not present then restricted is the effective setting param($computerName=$env:computerName) $reg = Get-WmiObject -List -Namespace root\\default -...
PowerShellCorpus/PoshCode/Get-NextPrime_1.ps1
Get-NextPrime_1.ps1
$primes = 2,3,5 #,7,11,13,17,19,23 $primeIndex = 0 function Get-NextPrime { [CmdletBinding(DefaultParameterSetName="KnownPrime")] param( [Parameter(Position=0,ParameterSetName="KnownPrime")] $knownPrime = $(if($primeIndex -lt $primes.Count){ $primes[$primeIndex] } else { $primes[-1] } ) , ...
PowerShellCorpus/PoshCode/Search cmdlet help.ps1
Search cmdlet help.ps1
function Search-Help($term) { Get-Command | Where { Get-Help -full -ea SilentlyContinue $_ | Out-String | Select-String $term } }
PowerShellCorpus/PoshCode/OpsMgr.psd1.ps1
OpsMgr.psd1.ps1
<# #Run the following code to create OpsMgr module #To Use run import-module OpsMgr; Start-OperationsManagerClientShell -ManagementServerName: "" -PersistConnection: $true -Interactive: $true; if (-not (test-path $home\\Documents\\WindowsPowerShell\\Modules\\OpsMgr)) {new-item $home\\Documents\\WindowsPowerShell\...
PowerShellCorpus/PoshCode/Delete AD Users.ps1
Delete AD Users.ps1
function Delete-ADUser { Param($userName = $(throw 'Enter a username to delete')) $searcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]"","(&(objectcategory=user)(sAMAccountName=$userName))") $user = $searcher.findone().GetDirectoryEntry() $user.psbase.DeleteTree() } $NumDays = 90 $Lo...
PowerShellCorpus/PoshCode/PowerShell CMatrix.ps1
PowerShell CMatrix.ps1
Set-StrictMode -off # # Module: PowerShell Console ScreenSaver Version 0.1 # Author: Oisin Grehan ( http://www.nivot.org ) # # A PowerShell CMatrix-style screen saver for true-console hosts. # # This will not work in Micrisoft's ISE, Quest's PowerGUI or other graphical hosts. # It should work fine in PowerShe...
PowerShellCorpus/PoshCode/where-property_1.ps1
where-property_1.ps1
function where-property([string] $PropertyName,[string]$SubProperty , $is,$isnot,$contains,$in,$SelectProperty) { process { $useprop = $SelectProperty Function _outobj { if ($useprop ) { , $_.$useprop } else { , $_ } } if ($is) ...
PowerShellCorpus/PoshCode/Trim Working Set for PID_1.ps1
Trim Working Set for PID_1.ps1
## Trim Working set Function TrimWorkingSet { param([int] $procid) <#.NOTES AUTHOR: Sunny Chakraborty(sunnyc7@gmail.com) WEBSITE: http://tekout.wordpress.com CREATED: 9/20/2012 This starts the Evil Monkey series of scripts. .DESCRIPTION MSDN - http://msdn.microsoft.com/en-us/library/windows/desktop/ms6862...
PowerShellCorpus/PoshCode/Live@Edu password reset.ps1
Live@Edu password reset.ps1
#---------------------------------------------- #region Application Functions #---------------------------------------------- function OnApplicationLoad { #Note: This function runs before the form is created #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path #No...
PowerShellCorpus/PoshCode/Compare-TwitterNames_1.ps1
Compare-TwitterNames_1.ps1
#This script will compare the names of the people you follow on Twitter #and the people following you. It returns a comparison object consisting #of the Twitter name of a subject and a side indicator - #"<=" means that you are following a subject who is not following you, #"=>" means that you are followed by so...
PowerShellCorpus/PoshCode/Select-Expand.ps1
Select-Expand.ps1
function Select-Expand { <# .Synopsis Like Select-Object -Expand, but with recursive iteration of a select chain .Description Takes a dot-separated series of properties to expand, and recursively iterates the output of each property ... .Parameter Property A collection of property names to expand. ...
PowerShellCorpus/PoshCode/Start-Job proxy function.ps1
Start-Job proxy function.ps1
<# Example on how to use Proxy Cmdlets in combination with object events. For more information see: http://blog.powershell.no/2011/02/07/powershell-using-proxy-cmdlets-in-combination-with-object-events For more information about proxy functions, see the following article on the Microsoft PowerShell Team ...
PowerShellCorpus/PoshCode/Debug Regex match_1.ps1
Debug Regex match_1.ps1
function Debug-Regex { <# .SYNOPSIS A very simple function to debug a Regex search operation and show any 'Match' results. (V2.1 Export Alias db & some patterns, 28 Jan 2012). .DESCRIPTION Sometimes it is easier to correct any regex usage if each match can be shown in context. This function will show each su...
PowerShellCorpus/PoshCode/Error handling PowerCLI.ps1
Error handling PowerCLI.ps1
$vmPath = "[Storage1] MyVM/MyVM.vmx" $vm = New-VM –VMHost "192.168.1.10" –VMFilePath $vmPath -Name MyVM # Check if there is an error and if so – handle it if (!$?) { if ($error[0].Exception –is [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.DuplicateName]) { # A VM with the same name already exists. Ch...
PowerShellCorpus/PoshCode/Invoke-Command_1.ps1
Invoke-Command_1.ps1
Param($file,$cmd,[switch]$whatif,[switch]$verbose) Begin{ function Ping-Server { Param([string]$srv) $pingresult = Get-WmiObject win32_pingstatus -f "address='$srv'" if($pingresult.statuscode -eq 0) {$true} else {$false} } $servers = @() } Process{ if($_) { ...
PowerShellCorpus/PoshCode/demo.ps1
demo.ps1
\n[45]: [IO.File]::ReadAllLines( "C:\\Users\\Joel\\Sites\\webalizer.current" ).Length 31873 [46]: (gc C:\\Users\\Joel\\Sites\\webalizer.current).Length 31873 [47]: gph 2 Duration Average Lines Words Chars Type Commmand -------- ------- ----- ----- ----- ---- -------- 0.07910 0.07910 1 3 73 Co...
PowerShellCorpus/PoshCode/ScheduledTasks_1.ps1
ScheduledTasks_1.ps1
# Windows Scheduled Tasks Management PowerShell Module # http://powershell.codeplex.com Function Get-ScheduledTasks { [CmdletBinding()] param ( [ValidateNotNullOrEmpty()] [string] $TaskName, [string] $HostName ) process { if ( $HostName ) { $HostName = "/S $HostName" } $ScheduledTasks = S...
PowerShellCorpus/PoshCode/LibraryMSCS_3.ps1
LibraryMSCS_3.ps1
# ------------------------------------------------------------------------ ### <Script> ### <Author> ### Chad Miller ### </Author> ### <Description> ### Defines functions for working with Microsoft Cluster Service (MSCS) ### </Description> ### <Usage> ### . ./LibraryMSCS.ps1 ### </Usage> ### </Script> # --...
PowerShellCorpus/PoshCode/Remove-LocalProfile_1.ps1
Remove-LocalProfile_1.ps1
<# .SYNOPSIS Interactive menu that allows a user to connect to a local or remote computer and remove a local profile. .DESCRIPTION Presents an interactive menu for user to first make a connection to a remote or local machine. After making connection to the machine, the user is presented with...
PowerShellCorpus/PoshCode/RSS Enclosure Downloader.ps1
RSS Enclosure Downloader.ps1
# author: Alexander Grofl # http://www.therightstuff.de/2008/07/25/RSS+Enclosure+Downloader+In+PowerShell.aspx $feed=[xml](New-Object System.Net.WebClient).DownloadString("http://the/rss/feed/url") foreach($i in $feed.rss.channel.item) { $url = New-Object System.Uri($i.enclosure.url) $url.ToString() $url.Se...
PowerShellCorpus/PoshCode/get windows product key_5.ps1
get windows product key_5.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/HelpModules 1.0.ps1
HelpModules 1.0.ps1
# HelpModules # A Module for generating module stubs so you can Update-Help (or Save-Help) # Includes two options for reading the help from those modules (StubFunctions or Get-ModuleHelp) # 1.0 - 2013/2/1 - Initial release Friday, Feb 1st, 2013 $PSModuleHelpRoot = Convert-Path "~\\Documents\\WindowsPowerShe...
PowerShellCorpus/PoshCode/Test-Port_2.ps1
Test-Port_2.ps1
function Test-Port{ <# .SYNOPSIS Tests port on computer. .DESCRIPTION Tests port on computer. .PARAMETER computer Name of server to test the port connection on. .PARAMETER port Port to test .PARAMETER tcp Use tcp port .PARAMETER udp Use udp port .PARAMETER UDP...
PowerShellCorpus/PoshCode/Easy Migration Tool v2.1.ps1
Easy Migration Tool v2.1.ps1
#Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: Richard Yaw # Generated On: 09/12/2010 # # Easy Migration Script for VMware (Version 2.0) # - Added a "Reload Tasks" feature. # - Fixed issue with the Undo feature for S...
PowerShellCorpus/PoshCode/Get-SiSReport_4.ps1
Get-SiSReport_4.ps1
Function Get-SiSReport { <# .SYNOPSIS Get the overall SIS usage information. .DESCRIPTION This function uses the sisadmin command to get the usage information for a SIS enabled drive. .PARAMETER SisDisk The drive letter of a disk that ...
PowerShellCorpus/PoshCode/Skip-Object_1.ps1
Skip-Object_1.ps1
function Skip-Object { param( [int]$First = 0, [int]$Last = 0, [int]$Every = 0, [int]$UpTo = 0, [Parameter(Mandatory=$true,ValueFromPipeline=$true)] $InputObject ) begin { if($Last) { $Queue = new-object System.Collections.Queue $Last } $e = $every; $UpTo++; $u = 0 } process { ...
PowerShellCorpus/PoshCode/Add-Slide.ps1
Add-Slide.ps1
function Add-Slide($pres, $maxShared, $vmUsages, $vmShared, $maxVM, $vmLoad) { $slide = $pres.slides.range(1).duplicate() #$totalSlides = ($pres.slides | Measure-Object).Count #$pres.slides.range(2).moveto($totalSlides) #region 1 # Add all the boxes. Skip the first position. $i = 1 foreach ($position in...
PowerShellCorpus/PoshCode/Get-StringRange_1.ps1
Get-StringRange_1.ps1
## Works great for a..f or g..a ## BUT WEIRD for Z..a or A..a or anything non-latin function Get-CharRange ( [char]$Start, [char]$End ) { [char[]]($Start..$End) } ## Cleaner output. Try Get-LetterRange A z vs. Get-CharRange A z ## And international. ## Get-LetterRange 0x0370 0x03FF Greek ## You just specify ...
PowerShellCorpus/PoshCode/Get Twitter RSS Feed_4.ps1
Get Twitter RSS Feed_4.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/HttpRest 1.1.1.ps1
HttpRest 1.1.1.ps1
#requires -version 2.0 ## HttpRest module #################################################################################################### ## Initial stages of changing HttpRest into a v2-only module ## Based on the REST api from MindTouch's Dream SDK ## ## INSTALL: ## You need mindtouch.dream.dll (mindtouch...
PowerShellCorpus/PoshCode/ConvertToStringData.ps1
ConvertToStringData.ps1
function ConvertTo-StringData { Begin { $string = "@{`n" function Expand-Value { param($value) if ($value -ne $null) { switch ($value.GetType().Name) { 'String' { "`"$value`"" } ...
PowerShellCorpus/PoshCode/BER Encoding Module.ps1
BER Encoding Module.ps1
<# .SYNOPSIS BER encoding library .DESCRIPTION Takes ASN types integer, octet (string), octet (byte array), and OID (string) values and encodes into byte array using Basic Encoding Rules (BER) BER encoding is used for SNMP, X.509 certificates, etc. There will be a companion BER decoding l...
PowerShellCorpus/PoshCode/Set-Computername_5.ps1
Set-Computername_5.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-Comment.ps1
Get-Comment.ps1
#Requires -version 3.0 <# .Synopsis Gets all of the comments from a script .Description Uses the PowerShell 3 Parser to figure out what's a comment #> [CmdletBinding()] param( # The script, or the path to a script file [String]$Script ) # Convert paths to script contents (otherwise, assume...
PowerShellCorpus/PoshCode/Convert-ToMP3.ps1
Convert-ToMP3.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=$outpu...
PowerShellCorpus/PoshCode/NTFS ACLs Folder Tree_3.ps1
NTFS ACLs Folder Tree_3.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-Weather.ps1
Get-Weather.ps1
## Get-Weather ## Parse and display the current weather and forecast from yahoo RSS ## Note that you _could_ modify this a bit to return "current condition" and "forecast" objects ## but for now, it just prints them out in a relatively nice format #################################################################...
PowerShellCorpus/PoshCode/Get-Pecoff.ps1
Get-Pecoff.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/Findup_25.ps1
Findup_25.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-PrimaryIPAddress.ps1
Get-PrimaryIPAddress.ps1
[system.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | Where-Object { $_.GetIPProperties().GatewayAddresses } | ForEach-Object { $_.GetIPProperties().UnicastAddresses| ForEach-Object { $_.Address.IPAddressToString } }
PowerShellCorpus/PoshCode/Get-Speech.ps1
Get-Speech.ps1
#requires -pssnapin PSEventing -version 1.1 ## http://www.codeplex.com/PSEventing/ ## ALSO REQUIRES .NET 3.0 # --------------------------------------------------------------------------- ## <Script> ## <Author> ## Joel "Jaykul" Bennett ## </Author> ## <Description> ## Prompts the user for a selection via voice...
PowerShellCorpus/PoshCode/Get-MACFromIP.ps1
Get-MACFromIP.ps1
Function Get-MACFromIP { param ($IPAddress) $sign = @" using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.NetworkInformation; using System.Runtime.InteropServices; public static class NetUtils { [System.Runtime.InteropServices.DllImport("iphlpapi.dll...
PowerShellCorpus/PoshCode/finddupe_7.ps1
finddupe_7.ps1
function Get-MD5([System.IO.FileInfo] $file = $(throw 'Usage: Get-MD5 [System.IO.FileInfo]')) { $stream = $null; $cryptoServiceProvider = [System.Security.Cryptography.MD5CryptoServiceProvider]; $hashAlgorithm = new-object $cryptoServiceProvider $stream = $file.OpenRead(); $hashByteArray = $hashA...
PowerShellCorpus/PoshCode/Start-ProcessAsAdministr.ps1
Start-ProcessAsAdministr.ps1
function Start-ProcessAsAdministrator { <# .ForwardHelpTargetName Start-Process .ForwardHelpCategory Cmdlet #> [CmdletBinding(DefaultParameterSetName='Default')] param( [Parameter(Mandatory=$true, Position=0)] [Alias('PSPath')] [ValidateNotNullOrEmpty()] [System.String...
PowerShellCorpus/PoshCode/Deleted-ObjectsAD_2.ps1
Deleted-ObjectsAD_2.ps1
param( $Domen, [string[]]$ObjectsDeleted ) function Ping ($Name){ $ping = new-object System.Net.NetworkInformation.Ping if ($ping.send($Name).Status -eq "Success") {$True} else {$False} trap {Write-Verbose "Error Ping"; $False; continue} } [string[]]$ObjectPath [string[]]$Disks [string[]]...
PowerShellCorpus/PoshCode/de04269d-38ca-4bb2-8559-9bd6072c319f.ps1
de04269d-38ca-4bb2-8559-9bd6072c319f.ps1
#========================================================================== # NAME: getunknownsids.ps1 # # AUTHOR: Stephen Wheet # Version: 4.0 # Date: 6/11/10 # # COMMENT: # This script was created to find unknown SIDs or old domain permissions # on folders. It ignores folders where inheirtance is turned ...
PowerShellCorpus/PoshCode/Shell.ShellLink.ps1
Shell.ShellLink.ps1
## With thanks to Steve McMahon and his article: ## http://vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Creating_and_Modifying_Shortcuts/article.asp ## ## After executing Add-Type, below, you'll be able to: ## new-object Shell.ShellLink ".\\Some Shortcut.lnk" Add-Type -Ref System.Drawing, System.Wind...
PowerShellCorpus/PoshCode/wpf datagrid xaml.ps1
wpf datagrid xaml.ps1
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Window" Title="DataGrid Binding" Width="640" Height="480"> <Grid > <TextBlock Height="24" Margin="8,8,8,0" TextWrapping="Wrap" Text="DataGrid" VerticalAlignment="Top" F...
PowerShellCorpus/PoshCode/chkhash_19.ps1
chkhash_19.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/Network Config _ Excel.ps1
Network Config _ Excel.ps1
$excel = New-Object -comobject Excel.Application $excel.visible = $False #Change to True to see the excel build $wbook = $excel.Workbooks.Add() $wsheet = $wbook.Worksheets.Item(1) $wsheet.Cells.Item(1,1) = "Date" $wsheet.Cells.Item(1,2) = "Server" $wsheet.Cells.Item(1,3) = "NETID" $wsheet.Cells.Item(1,4) = "Desc...
PowerShellCorpus/PoshCode/The Letter Diamond.ps1
The Letter Diamond.ps1
## Write a program which draws a diamond of the form illustrted ## below. The letter which is to appear at the widest point of the ## figure (E in the example) is to be specified as the input data. ## A ## B B ## C C ## D D ## E E ## D D ## ...
PowerShellCorpus/PoshCode/Get_Set Signature (CTP2)_2.ps1
Get_Set Signature (CTP2)_2.ps1
#Requires -version 2.0 ## Authenticode.psm1 #################################################################################################### ## Wrappers for the Get-AuthenticodeSignature and Set-AuthenticodeSignature cmdlets ## These properly parse paths, so they don't kill your pipeline and script if you incl...
PowerShellCorpus/PoshCode/Connect-VMHost.ps1
Connect-VMHost.ps1
#requires -version 2 -pssnapin VMware.VimAutomation.Core Function Connect-VMHost { <# .Summary Used to Connect a disconnected host to vCenter. .Parameter VMHost VMHost to reconnect to virtual center .Example Get-VMHost | Where-Object {$_.state -eq "Disconnected"} | Conne...
PowerShellCorpus/PoshCode/VMware _ Windows Admin.ps1
VMware _ Windows Admin.ps1
#======================================================================== # Created on: 5/17/2012 2:03 PM # Created by: Clint Jones # Organization: Virtually Genius! # Filename: Get-VMHostVersions #======================================================================== #Import modules Add-PSSnapin "Vm...
PowerShellCorpus/PoshCode/8fad46f9-26e1-4da7-8cc9-eb8a10d893dc.ps1
8fad46f9-26e1-4da7-8cc9-eb8a10d893dc.ps1
$devEnvArgs = '"' + "$pwd"+"\\Installer\\myInstaller.sln" + '"'; $devSwitches = '"' + "/rebuild Release 2>&1" + '"'; $output = &$vsExe $devEnvArgs $devSwitches;
PowerShellCorpus/PoshCode/Get Twitter RSS Feed_7.ps1
Get Twitter RSS Feed_7.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/Import-Certificate_2.ps1
Import-Certificate_2.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/ISEFun.psm1.ps1
ISEFun.psm1.ps1
# Module version 0.1 # 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/LibraryMSCS_2.ps1
LibraryMSCS_2.ps1
# ------------------------------------------------------------------------ ### <Script> ### <Author> ### Chad Miller ### </Author> ### <Description> ### Defines functions for working with Microsoft Cluster Service (MSCS) ### </Description> ### <Usage> ### . ./LibraryMSCS.ps1 ### </Usage> ### </Script> # --...
PowerShellCorpus/PoshCode/0ddea161-baf2-439c-b797-afb5c636692f.ps1
0ddea161-baf2-439c-b797-afb5c636692f.ps1
#Variables $Date = Get-Date $TempReport = $env:TEMP + "\\temp.csv" $FinalReport = $env:USERPROFILE + "\\" + $Date.Year + "_" + $Date.Month + "_" + $Date.Day + "_" + $Date.Hour + ":" + $Date.Minute + "_Scheduled_Task_Report.csv" $title = Write-Host "Scheduled Task Reporter" -ForegroundColor green $message = Write...
PowerShellCorpus/PoshCode/Move-Mailbox 2010.ps1
Move-Mailbox 2010.ps1
$DistGroup = XC2010Move $MB2Move = Get-DistributionGroup XC2010Move | Get-DistributionGroupMember | Get-Mailbox | Where {($_.RecipientTypeDetails -eq "LegacyMailbox") -and ($_.MailboxMoveStatus -eq ‘None’)} | Get-Random -Count 20 $batch = "MoveMB_{0:ddMMM_yyyy}" -f (Get-Date) ForEach ($SingleMailbox in $MB2Move) {Ne...
PowerShellCorpus/PoshCode/Set-UserCannotChangePass.ps1
Set-UserCannotChangePass.ps1
#########1#########2#########3#########4#########5#########6#########7#########8#########9#########1 #########0#########0#########0#########0#########0#########0#########0#########0#########0#########0 # # Author: Erik McCarty # # Description: Set the "user Cannot Change Password" property on an active # director...
PowerShellCorpus/PoshCode/Pomodoro Module.ps1
Pomodoro Module.ps1
#PomoDoro Module (make sure its a PS1) #12-3-2011 Karl Prosser #example #import-module C:\\amodule\\Pomodoro.psm1 -force #Start-Pomodoro -ShowPercent -Work "coding" -UsePowerShellPrompt #future todos # -limit , a number (by default 0 meaning forever) that will only run the pomodoro that many times # -Confi...
PowerShellCorpus/PoshCode/DekiWiki Module 1.5.ps1
DekiWiki Module 1.5.ps1
## DekiWiki Module 1.5 #require -version 2.0 ## Depends on the HttpRest script-module: ## http :// huddledmasses.org/using-rest-apis-from-powershell-with-the-dream-sdk/ #################################################################################################### ## The first of many script cmd...
PowerShellCorpus/PoshCode/Audit File Share Perms.ps1
Audit File Share Perms.ps1
Function Get-SharePermissions($ShareName){ $Share = Get-WmiObject win32_LogicalShareSecuritySetting -Filter "name='$ShareName'" if($Share){ $obj = @() $ACLS = $Share.GetSecurityDescriptor().Descriptor.DACL foreach($ACL in $ACLS){ $User = $ACL.Trustee.Name i...
PowerShellCorpus/PoshCode/Scan Remote Event Logs.ps1
Scan Remote Event Logs.ps1
#requires -version 2.0 function Scan-EventLogs { <# .SYNOPSIS Scan event logs on specified computer(s) and return a sorted collection events to review. .Description Uses PowerShell Remoting with Invoke-Command and Get-EventLog to fetch a list of enabled event log...
PowerShellCorpus/PoshCode/Findup_26.ps1
Findup_26.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/NewUser in AD_OCS_Email_1.ps1
NewUser in AD_OCS_Email_1.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/Sync-Time_1.ps1
Sync-Time_1.ps1
function sync-time( [string] $server = "clock.psu.edu", [int] $port = 37) { $servertime = get-time -server $server -port $port -set #leave off -set to just check the remote time write-host "Server time:" $servertime write-host "Local time :" $(date) }
PowerShellCorpus/PoshCode/VerifyCategoryRule_2.ps1
VerifyCategoryRule_2.ps1
2RIXu3 this is delisious! xfather123
PowerShellCorpus/PoshCode/Write-Log_3.ps1
Write-Log_3.ps1
function Write-Log { #region Parameters [cmdletbinding()] Param( [Parameter(ValueFromPipeline=$true,Mandatory=$true)] [ValidateNotNullOrEmpty()] [string] $Message, [Parameter()] [ValidateSet(“Error”, “Warn”, “Info”)] [string] $Level = “Info”, [Parameter()] [Switch] $NoConsole...
PowerShellCorpus/PoshCode/Productivity Calculator.ps1
Productivity Calculator.ps1
<# Author: mazakane This short script converts Time settings and displays a "productivity" Report with a goal of 81% Example: get-productivity -Start 8:00 -End 17:00 #> function get-Productivity{ param( $start, $end ) $a = ([datetime]::Parse("$start")) $b = ([datetime]::Parse("$end")) ...
PowerShellCorpus/PoshCode/PowerBot 2.0.ps1
PowerBot 2.0.ps1
## PowerBot 2.0 ## A simple framework to get you started writing your own IRC bots in PowerShell #################################################################################################### ## Requires Meebey.SmartIrc4net.dll to be in your ...\\WindowsPowerShell\\Libraries\\ ## You can get Meebey.SmartIrc4n...
PowerShellCorpus/PoshCode/Hash Checker_4.ps1
Hash Checker_4.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/Ping Alert Script.ps1
Ping Alert Script.ps1
#Email Alert Parameters $to = "user@mydomain.com" $from = "unreachable@mydomain.com" $smtpserver = "my_exchange_server" #Array of computers to test $Computers = ("comp1" , "comp2" , "comp3" , "comp4") #Variable to hold INT value 0 $zero = 0 Foreach ($Computer in $Computers) { if...
PowerShellCorpus/PoshCode/Find Local Group Members_7.ps1
Find Local Group Members_7.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/Deploy VM with Static IP_3.ps1
Deploy VM with Static IP_3.ps1
# 1. Create a simple customizations spec: $custSpec = New-OSCustomizationSpec -Type NonPersistent -OSType Windows ` -OrgName “My Organization” -FullName “MyVM” -Domain “MyDomain” ` –DomainUsername “user” –DomainPassword “password” # 2. Modify the default network customization settings: $custSpec | Get-OSCu...
PowerShellCorpus/PoshCode/Invoke-ScriptThatRequire.ps1
Invoke-ScriptThatRequire.ps1
###########################################################################\n##\n## Invoke-ScriptThatRequiresSta\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\nD...
PowerShellCorpus/PoshCode/Stored Credential Code_1.ps1
Stored Credential Code_1.ps1
#STORED CREDENTIAL CODE $AdminName = Read-Host "Enter your Admin AD username" $CredsFile = "C:\\$AdminName-PowershellCreds.txt" $FileExists = Test-Path $CredsFile if ($FileExists -eq $false) { Write-Host 'Credential file not found. Enter your password:' -ForegroundColor Red Read-Host -AsSecureString | ConvertF...
PowerShellCorpus/PoshCode/Get-InvocationInfo.ps1
Get-InvocationInfo.ps1
##############################################################################\n##\n## Get-InvocationInfo\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\nDispl...
PowerShellCorpus/PoshCode/SCOM-RunRemoteExecutable.ps1
SCOM-RunRemoteExecutable.ps1
# ============================================================================================== # # Microsoft PowerShell Source File Ś Created with SAPIEN Technologies PrimalScript 2007 # # NAME: SCOM-RunRemoteExecutable.ps1 # # AUTHOR: Jeremy D. Pavleck , Pavleck.NET # DATE : 9/13/2008 # # COMMENT: This is ...
PowerShellCorpus/PoshCode/Invoke-SqlCmd_6.ps1
Invoke-SqlCmd_6.ps1
function Invoke-Sqlcmd2 { param ( [string]$ServerInstance="localhost", [string]$Database, [string]$Query, [Int32]$CommandTimeout=30 ) $connectionString = "Server={0};Database={1};Integrated Security=True" -f $ServerInstance, $Database $connection = New...
PowerShellCorpus/PoshCode/Set-ExcludeFromPeek.ps1
Set-ExcludeFromPeek.ps1
Add-Type -Type @" using System; using System.Runtime.InteropServices; namespace Huddled { public static class Dwm { [DllImport("dwmapi.dll", PreserveSig = false)] public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); [Flags] public...
PowerShellCorpus/PoshCode/New-Exch2010NlbCluster.ps1
New-Exch2010NlbCluster.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/Send-RTMTask.ps1
Send-RTMTask.ps1
#—————————————————————————— # Func/Sub Name: Send-RTMTask # Purpose: Sends a task to the Remember The Milk system via email. # Arguments Supplied: # Return Value: # External Reference: #—————————————————————————— function Send-RTMTask { param( [string]$TaskName=$(Throw "need TaskName"), $Priority, ...
PowerShellCorpus/PoshCode/Get-User_3.ps1
Get-User_3.ps1
function Get-User($user) { # this function should be passed the CN of the user to be returned $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() $root = [ADSI] "LDAP://$($dom.Name)" $searcher = New-Object System.DirectoryServices.DirectorySearcher $root $searcher.filter = "(&(objec...
PowerShellCorpus/PoshCode/Open-Solution.ps1
Open-Solution.ps1
function Open-Solution([string]$path = ".") { $sln_files = Get-ChildItem $path -Include *.sln -Recurse if($sln_files -eq $null) { Write-Host "No Solution file found" return } if($sln_files.Count) { # There is more than one do { Write-Host "Please select file (or Ctrl+C to quit)" ...
PowerShellCorpus/PoshCode/Finding Old or Unused Ac.ps1
Finding Old or Unused Ac.ps1
$dcs = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain().DomainControllers | select name $startdate = get-date('1/1/1601') $lst = new-Object System.Collections.ArrayList foreach ($dc in $dcs) { $root = [ADSI] LDAP://$($dc.Name):389 $searcher = New-Object System.DirectoryServices.Directory...
PowerShellCorpus/PoshCode/9ef43b00-ae12-4e41-b331-af2bdfba35c1.ps1
9ef43b00-ae12-4e41-b331-af2bdfba35c1.ps1
#alias,addnewemailaddress import-csv .\\source.csv | foreach { $user = Get-Mailbox $_.alias $user.emailAddresses+= $_.addnewemailaddress $user.primarysmtpaddress = $_.addnewemailaddress Set-Mailbox $user -emailAddresses $user.emailAddresses set-Mailbox $user -PrimarySmtpAddress $user.primarysmtpaddress }
PowerShellCorpus/PoshCode/Set-Watcher.ps1
Set-Watcher.ps1
############################################################################### # Use Unregister-Event -SourceIdentifier <name> -Force (to stop an Event). # Include script in $profile to register all these events. Modify to suit own # requirements and comment out any of the examples below that are not needed. # Pl...
PowerShellCorpus/PoshCode/Convert-ToCHexString_4.ps1
Convert-ToCHexString_4.ps1
function Convert-ToCHexString { [CmdletBinding()] param ( [Parameter(ValueFromPipeline=$true,Mandatory=$true)][string]$str ) process { ($str.ToCharArray() | %{ "0x{0:X2}" -f [int]$_ }) -join ',' } }
PowerShellCorpus/PoshCode/TabExpansion_3.ps1
TabExpansion_3.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> ## $foo[0].<tab> ## $foo[0].n.b<tab> ## $function:a<tab> ##...
PowerShellCorpus/PoshCode/SQLite Read _ Write_1.ps1
SQLite Read _ Write_1.ps1
# Make sure SQLite.Interop.dll is in the same directory as System.Data.SQLite.dll $scriptDir = "Path to your SQLite DLL" Add-Type -Path "$scriptDir\\System.Data.SQLite.dll" ############### SAMPLE USAGE ################### ### Querying: ### ### $readQuery = "SELECT * FROM TABLE" ### $dataArray = $SQLite.q...
PowerShellCorpus/PoshCode/Get-GrowthRate_1.ps1
Get-GrowthRate_1.ps1
function Get-GrowthRate { param( $Start, $End, $Period ) @@ $rate = [math]::Abs( [math]::Pow( ( $End / $Start ),( 1 / $Period - 1 ) ) - 1 ) "{0:P}" -f $rate }
PowerShellCorpus/PoshCode/Modal File Dialogs.ps1
Modal File Dialogs.ps1
Add-Type -TypeDefinition @" using System; using System.Windows.Forms; public class Win32Window : IWin32Window { private IntPtr _hWnd; public Win32Window(IntPtr handle) { _hWnd = handle; } public IntPtr Handle { get { return _hWnd; } } } "@ -Referenced...
PowerShellCorpus/PoshCode/New-ISEMenu_1.ps1
New-ISEMenu_1.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...