full_path
stringlengths
31
232
filename
stringlengths
4
167
content
stringlengths
0
48.3M
PowerShellCorpus/PoshCode/Sort IE Favorites.ps1
Sort IE Favorites.ps1
$Results = gci $env:userprofile\\favorites -rec -inc *.url | ? {select-string -inp $_ -quiet "^URL=http"} | select @{Name="Name"; Expression={[IO.Path]::GetFileNameWithoutExtension($_.FullName)}}, @{Name="URL"; Expression={get-content $_ | ? {$_ -match "^URL=http"} | % {$_.Substring(4)}}} New-Item $env:userprofil...
PowerShellCorpus/PoshCode/Check PowerShell version.ps1
Check PowerShell version.ps1
#Check if PowerShell version 3 or higher is installed if($host.Version.Major -lt 3) { Write-Host "PowerShell Version 3 or higher needs to be installed" -ForegroundColor Red Write-Host "Windows Management Framework 3.0 - RC" -ForegroundColor Magenta Write-Host "http://www.microsoft.com/en-us/download/details...
PowerShellCorpus/PoshCode/Function Run-Script_2.ps1
Function Run-Script_2.ps1
################################################################################# # This function should be included in the PowerShell ISE profile.ps1 and it will # display the start and end times of any scripts started by clicking 'Run Script' # in the Add-ons Menu, or F2; additionally they will be logged to the S...
PowerShellCorpus/PoshCode/Get-RemoteRegistry_4.ps1
Get-RemoteRegistry_4.ps1
## Get-RemoteRegistry ######################################################################################## ## Version: 2.2 ## + Added a feature that will return the (Default) values for a key. ## These are referenced as ."(Default)". ## I didn't want to use just "Default" as the property name because of...
PowerShellCorpus/PoshCode/Fill-ErUp.ps1
Fill-ErUp.ps1
function Fill-ErUp { <# .Synopsis The function will append random integers to a specified file through $Path until it reaches the $Size requirement. .Description Fills a file up with random integers until the file size is equal to the desired size. Used to increase file mememory size. .Parameter FileP...
PowerShellCorpus/PoshCode/CenturionPortal.ps1
CenturionPortal.ps1
## New-CodeSigningCert.ps1 ######################################################################################################################## ## Does the setup needed to self-sign PowerShell scripts ... ## Generates a "test" self-signed root Certificate Authority ## And then generates a code-signing certific...
PowerShellCorpus/PoshCode/Select-CLSCompliant_1.ps1
Select-CLSCompliant_1.ps1
function Select-CLSCompliant { #.Synopsis # Outputs the same as "Select-Object *" with basic error handling for properties that are not CLS Compliant [CmdletBinding()] param([Parameter(ValueFromPipeline=$true)]$InputObject) process { foreach($in in $InputObject) { $In | Select-Object * trap ...
PowerShellCorpus/PoshCode/ScheduledTasks.ps1
ScheduledTasks.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/Out-AnsiGraph_1.ps1
Out-AnsiGraph_1.ps1
# # Out-AnsiGraph.psm1 # Author: xcud # History: # v0.1 September 21, 2009 initial version # function Out-AnsiGraph($Parameter1=$null) { BEGIN { $q = new-object Collections.queue } PROCESS { if($_) { $name = $_.($Parameter1[0]); $val = $_.($Parameter1[1]) if($max -lt $val) { ...
PowerShellCorpus/PoshCode/LibrarySqlData.ps1
LibrarySqlData.ps1
####################### function Get-SqlData { param([string]$serverName=$(throw 'serverName is required.'), [string]$databaseName=$(throw 'databaseName is required.'), [string]$query=$(throw 'query is required.')) Write-Verbose "Get-SqlData serverName:$serverName databaseName:$databaseName que...
PowerShellCorpus/PoshCode/fc6a6ed7-a2a0-4a41-af75-9b06c4fba5de.ps1
fc6a6ed7-a2a0-4a41-af75-9b06c4fba5de.ps1
#======================================================================== # Code Generated By: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.15 # Generated On: 2/6/2013 2:58 AM # Generated By: Manoj Nair # Organization: Self #======================================================================== #-----...
PowerShellCorpus/PoshCode/Check e-mail access type.ps1
Check e-mail access type.ps1
$ErrorActionPreference = "silentlycontinue" $login = read-host -prompt "Type the user login" $Status = @( Get-ADuser $login | select SamAccountName).count If($Status -eq 0) { Write-Host No such user exists! -FOREGROUNDCOLOR RED ./the_script_name.ps1 } Else {Write-Host Working on it! -FOREGROUNDCOLOR ...
PowerShellCorpus/PoshCode/Firefox Bookmarks By Key.ps1
Firefox Bookmarks By Key.ps1
if (!( gmo ShowUI)) {ipmo showui} if(!(Get-Command DataGrid -ErrorAction SilentlyContinue)) { Add-UIFunction -Type System.Windows.Controls.DataGrid } if(!(Get-Command DataGridTextColumn -ErrorAction SilentlyContinue)) { Add-UIFunction -Type System.Windows.Controls.DataGridTextColumn } if(!(Get-Com...
PowerShellCorpus/PoshCode/PowerOAuth Beta 2.ps1
PowerOAuth Beta 2.ps1
if(@(Import-ConstructorFunctions -Path "$PSScriptRoot\\Types_Generated").Count -lt 3) { Add-ConstructorFunction -T Hammock.Authentication.OAuth.OAuthCredentials, Hammock.RestClient, Hammock.RestRequest -Path "$PSScriptRoot\\Types_Generated" } $RequestToken = "request_token" $AccessToken = "access_token" $Auth...
PowerShellCorpus/PoshCode/New-RDP.ps1
New-RDP.ps1
######################################################################################################################## # NAME # New-RDP # # SYNOPSIS # Creates a new RDP file to store Remote Desktop connection settings. # # SYNTAX # Start-RDP [-Path] <string> [[-Server] <string>] [-PassThru] [-Forc...
PowerShellCorpus/PoshCode/6bdd2502-383e-47c0-9f8c-f6424b6ba672.ps1
6bdd2502-383e-47c0-9f8c-f6424b6ba672.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 SilentlyCont...
PowerShellCorpus/PoshCode/Get-FileEncoding_5.ps1
Get-FileEncoding_5.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/LibraryMSCS_4.ps1
LibraryMSCS_4.ps1
# ------------------------------------------------------------------------ ### <Script> ### <Author> ### Chad Miller ### </Author> ### <Description> ### Defines functions for working with Microsoft Cluster Service (MSCS) ### Updated 8/3/2011 ### Added Authentication PacketPrivacy to fix Access Denied errorso...
PowerShellCorpus/PoshCode/Invoke-ExecuteTSQL .ps1
Invoke-ExecuteTSQL .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-Credential 2.6.ps1
Get-Credential 2.6.ps1
## Get-Credential ## An improvement over the default cmdlet which has no options ... ################################################################################################### ## History ## v 2.6 Put back support for passing in the domain when getting credentials without prompting ## v 2.5 Added examples...
PowerShellCorpus/PoshCode/http___bestfreeipadgames.ps1
http___bestfreeipadgames.ps1
A man is not old as long as he is seeking something. A man is not old until regrets take the place of dreams. -----------------------------------
PowerShellCorpus/PoshCode/Test-VM_1.ps1
Test-VM_1.ps1
Function Test-VM { [cmdletbinding()] Param ( [Parameter(Mandatory=$true,Position=1)] [string[]]$Name, [Parameter(Mandatory=$true,Position=2)] [string[]]$ComputerName ) Process { $results = @() foreach ($cName in $ComputerName) { ...
PowerShellCorpus/PoshCode/Set Active Sync DeviceID_1.ps1
Set Active Sync DeviceID_1.ps1
# Requires a connection to Exchange Server, or Exchange Management Shell $s = New-PSSession -ConfigurationName Microsoft.Exchange -Name ExchMgmt -ConnectionUri http://ex14.domain.local/PowerShell/ -Authentication Kerberos Import-PSSession $s # Get all Client Access Server properties for all mailboxes with an Activ...
PowerShellCorpus/PoshCode/Test-CommandValidation.ps1
Test-CommandValidation.ps1
############################################################# # # PS II> Test-CommandValidation -command get-process | fl # VerbNounConvention : True # ReservedKeyWords : True # VerbConvention : True # # author: Walid Toumi ################################################...
PowerShellCorpus/PoshCode/RoboCopyWrapper.ps1
RoboCopyWrapper.ps1
# Robocopy example code for more info see the series on my blog # http://thepowershellguy.com/blogs/posh/archive/tags/robocopy/default.aspx ############################################################################################# ## Make RoboCopy Help Object ##################################################...
PowerShellCorpus/PoshCode/Get-FailingDrive_1.ps1
Get-FailingDrive_1.ps1
Function Get-FailingDrive { <# .SYNOPSIS Checks for any potentially failing drives and reports back drive information. .DESCRIPTION Checks for any potentially failing drives and reports back drive information. This only works against local hard drives using SMART technology. Reason values and th...
PowerShellCorpus/PoshCode/Test-VmMigration.ps1
Test-VmMigration.ps1
$vv = get-vm testsql17b | get-view $si = Get-View ServiceInstance -Server $global:DefaultVIServers[1] $hs = get-vmhost infesx52* $hv = $hs | Get-View $pool = $vv.ResourcePool $vmMoRef = $vv.MoRef $hsMoRef = $hv.MoRef $si = Get-View ServiceInstance -Server $global:DefaultVIServers[1] # this turned out to be futil...
PowerShellCorpus/PoshCode/New-IseFile.ps1
New-IseFile.ps1
function New-IseFile ($path = 'tmp_default.ps1') { $count = $psise.CurrentPowerShellTab.Files.count $null = $psIse.CurrentPowerShellTab.Files.Add() $Newfile = $psIse.CurrentPowerShellTab.Files[$count] $NewFile.SaveAs($path) $NewFile.Save([Text.Encoding]::default) $Newfile }
PowerShellCorpus/PoshCode/ConvertTo-MultiArray.ps1
ConvertTo-MultiArray.ps1
function ConvertTo-MultiArray { <# .Notes NAME: ConvertTo-MultiArray AUTHOR: Tome Tanasovski Website: http://powertoe.wordpress.com Twitter: http://twitter.com/toenuff Version: 1.0 CREATED: 11/5/2010 LASTEDIT: 11/5/2010 1.0 Initial Release .Synopsis Converts a collection of PowerShell obj...
PowerShellCorpus/PoshCode/MIFParser.ps1
MIFParser.ps1
param ($fileName, $computerName=$env:ComputerName) ####################### function ConvertTo-MIFXml { param ($mifFile) $mifText = gc $mifFile | #Remove illegal XML characters % { $_ -replace "&", "&amp;" } | % { $_ -replace"'", "&apos;" } | % { $_ -replace "<", "&lt;" } | % {...
PowerShellCorpus/PoshCode/Expand-ZipFile.ps1
Expand-ZipFile.ps1
function Expand-ZipFile { param { $zipPath, $destination, [switch] $quiet } $shellApplication = new-object -com shell.application $zipPackage = $shellApplication.NameSpace($zipPath) $destinationFolder = $shellApplication.NameSpace($destination) # CopyHere vOpti...
PowerShellCorpus/PoshCode/ConvertTo-Function.ps1
ConvertTo-Function.ps1
## ConvertTo-Function ## By Steven Murawski (http://www.mindofroot.com / http://blog.usepowershell.com) ################################################################################################### ## Usage: ## ./ConvertTo-Function Get-Server.ps1 ## dir *.ps1 | ./convertto-Function ########################...
PowerShellCorpus/PoshCode/whoami_3.ps1
whoami_3.ps1
function Get-UserStatus { <# .Synopsis Get extended information about local user. .Description There is no input arguments, just specify Get-UserStatus or his alias whoami. .Link http://msdn.microsoft.com/en-us/library/system.security.principal.aspx http://poshcode....
PowerShellCorpus/PoshCode/Invoke-ScriptBlockClosur.ps1
Invoke-ScriptBlockClosur.ps1
##############################################################################\n##\n## Invoke-ScriptBlockClosure\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...
PowerShellCorpus/PoshCode/Get-NaCifs.ps1
Get-NaCifs.ps1
# Glenn Sizemore www . Get-Admin . Com # Requires the NetApp OnTap SDK v3.5 # # Will connect to the destination Filer and retrieve detailed information on every # Cifs share. This function will not retrieve permissions. # # Usage: # Connect to the filler # $Filer = 'TOASTER' # $NetApp = New-Object NetApp.Mana...
PowerShellCorpus/PoshCode/Findup_5.ps1
Findup_5.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; namespace Findup { public class FileInfoExt { public FileInfoExt(FileInfo fi) ...
PowerShellCorpus/PoshCode/Publish-File_1.ps1
Publish-File_1.ps1
# Note that this version will not descend directories. function Publish-File { param ( [parameter( Mandatory = $true, HelpMessage="URL pointing to a SharePoint document library (omit the '/forms/default.aspx' portion)." )] [System.Uri]$Url, [system.Management.Automation.PSCredential]$Credential, [paramet...
PowerShellCorpus/PoshCode/e17dfa3f-0ecd-4124-a650-54cdf6ae6041.ps1
e17dfa3f-0ecd-4124-a650-54cdf6ae6041.ps1
Get-WmiObject -Class Win32_MountPoint | where {$_.Directory -like ‘Win32_Directory.Name="D:\\\\MDBDATA*"’} | foreach { $vol = $_.Volume Get-WmiObject -Class Win32_Volume | where {$_.__RELPATH -eq $vol} | Select @{Name="Folder"; Expression={$_.Caption}}, @{Name="Server"; Expression={$_.SystemName}...
PowerShellCorpus/PoshCode/Shaped WPF Windows.ps1
Shaped WPF Windows.ps1
$window = show -minw 300 -minh 300 -width 400 -height 400 -AllowsTransparency -WindowStyle none -Background transparent { grid { viewbox -stretch Uniform { Path -Fill "#80D0E0FF" -stroke red -strokethickness 4 ` -horizontalalign center -verticalalign center ` -data...
PowerShellCorpus/PoshCode/Convert File Encoding.ps1
Convert File Encoding.ps1
cd c:\\windows\\temp\\common foreach($File in get-childitem | where-object{($_.Extension -ieq '.PS1') -or ($_.Extension -ieq '.PSM1')}) { $FileName = $File.Name $TempFile = "$($File.Name).ASCII" @@ get-content $FileName | out-file $TempFile -Encoding ASCII remove-item $FileName rename...
PowerShellCorpus/PoshCode/Set-Computername_10.ps1
Set-Computername_10.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/finddupe_1.ps1
finddupe_1.ps1
param($dir = '.') 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(); $h...
PowerShellCorpus/PoshCode/TimeSyn HyperV Settings.ps1
TimeSyn HyperV Settings.ps1
<#Time Synchronization Status#> Write-Host "Time Synchronization Status" -ForegroundColor Yellow Write-Host "_______________________________" -ForegroundColor Yellow Write-Host $VMhost = Get-ItemProperty "HKLM:\\SOFTWARE\\Microsoft\\Virtual Machine\\Guest\\Parameters" | select -ExpandProperty physicalhost...
PowerShellCorpus/PoshCode/Out-LogFile Module.ps1
Out-LogFile Module.ps1
function Out-LogFile { <# .SYNOPSIS Output to log file. .DESCRIPTION Output to formatted log file. Default fomatting is: SEVERITY: dd-MM-yyyy HH:mm:ss: Message e.g. I: 25-06-2010 17:09:10: Started Processing .PARAMETER BackgroundColor Specifies the background colour when using -Write...
PowerShellCorpus/PoshCode/SMS_2.psm1.ps1
SMS_2.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/Inventory_2.ps1
Inventory_2.ps1
##############################################################################\n##\n## Inventory\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\nServes as the ...
PowerShellCorpus/PoshCode/Set-Computername_1.ps1
Set-Computername_1.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 -computername AnewName" if ($help) {Write-Host $usage;...
PowerShellCorpus/PoshCode/NIC Performance_1.ps1
NIC Performance_1.ps1
$cat = New-Object system.Diagnostics.PerformanceCounterCategory("Network Interface") $inst = $cat.GetInstanceNames() foreach ( $nic in $inst ) { $a = $cat.GetCounters( $nic ) $a | ft CounterName, { $_.NextValue() } -AutoSize }
PowerShellCorpus/PoshCode/Ayth_1.ps1
Ayth_1.ps1
# ======================================================================== # # Microsoft PowerShell Source File -- Created with PowerShell Plus Professional # # NAME: Disable-MassMailPF.ps1 # # AUTHOR: Darrin Henshaw , Ignition IT Canada Ltd. # DATE : 8/13/2008 # # COMMENT: Used to disable mail on an impo...
PowerShellCorpus/PoshCode/Import-BufferBox.ps1
Import-BufferBox.ps1
################################################################################################### ##### BUFFER UTILITIES SCRIPT FUNCTIONS AND SETUP ################################################################################################### ## A bunch of script functions for creating a simple in-console spl...
PowerShellCorpus/PoshCode/Quest Dynamic Group 001.ps1
Quest Dynamic Group 001.ps1
<# 2012.07.06 Information will be uploaded shortly. #>
PowerShellCorpus/PoshCode/Get-DiskSizeInfo.ps1
Get-DiskSizeInfo.ps1
Function Get-DiskSizeInfo { <# .DESCRIPTION Check the Disk(s) Size and remaining freespace. .PARAMETER ComputerName Specify the computername(s) .INPUTS System.String .OUTPUTS System.Management.Automation.PSObject .EXAMPLE ...
PowerShellCorpus/PoshCode/RegEx Quick Reference.ps1
RegEx Quick Reference.ps1
# get-regex.ps1 # # Displays .NET/C#/Powershell Regular Expression Quick Reference # # Author: Robbie Foust (rfoust@duke.edu) # # For best visual results, run "get-regex | ft -auto" function global:get-regex ([switch]$CharRep, [switch]$CharClass, [switch]$Anchors, [switch]$Comments, [switch]$Grouping, [switch]...
PowerShellCorpus/PoshCode/Set-OutlookSignature.ps1
Set-OutlookSignature.ps1
###########################################################################" # # NAME: Set-OutlookSignature.ps1 # # AUTHOR: Jan Egil Ring # # COMMENT: Script to create an Outlook signature based on user information from Active Directory. # Adjust the variables in the "Custom variables"-section # ...
PowerShellCorpus/PoshCode/Test-Port_6.ps1
Test-Port_6.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 .PARAMETE...
PowerShellCorpus/PoshCode/Windows Startup Script_2.ps1
Windows Startup Script_2.ps1
<#====================================================================================== File Name : Startup.ps1 Original Author : Kenneth C. Mazie : Description : This is a Windows startup script with pop-up notification and checks to : assure things are no...
PowerShellCorpus/PoshCode/LibraryProperties.ps1
LibraryProperties.ps1
##############################################################################\n##\n## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n##\n##############################################################################\n\nfilter Get-PropertyValue($property)\n{\n $_.$pro...
PowerShellCorpus/PoshCode/Watch-Process_2.ps1
Watch-Process_2.ps1
Function Watch-Process { <# .DESCRIPTION Creates an event handler for monitoring either process creation or deletion. This requires to be run as administrator. .SYNOPSIS Watches for process creation or deletion. .PARAMETER computerName Name of the remote computer. Make sure you have privileges to acces...
PowerShellCorpus/PoshCode/sqlps2.ps1
sqlps2.ps1
using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Resources; using System.Globalization; using System.Management.Automation; using System.Management.Automation.Runspaces; using System.Reflection; [assembly:RunspaceCo...
PowerShellCorpus/PoshCode/Copy-Function.ps1
Copy-Function.ps1
#Requires -Version 2.0 <# .Synopsis Copy a function from the current session to another session .Description Copies a function deffinition from the current session into any other session .Parameter Session The session(s) you want to define the function in .Parameter Name T...
PowerShellCorpus/PoshCode/Add -__ Get-Help -Full_1.ps1
Add -__ Get-Help -Full_1.ps1
$executionContext.SessionState.InvokeCommand.PostCommandLookupAction = { param($CommandName, $CommandLookupEventArgs) # Only for interactive commands (and that doesn't include "prompt") # I should exclude out-default so we don't handle it on every pipeline, but ... if($CommandLookupEventArgs.Comma...
PowerShellCorpus/PoshCode/.displayName to .cn.ps1
.displayName to .cn.ps1
Function ConvertUser { Process { ForEach($User In $_) { $strFilter = “(&(objectCategory=user)(displayName=$User))” $objDomain = New-Object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.PageSize = 1...
PowerShellCorpus/PoshCode/Get Twitter RSS Feed_2.ps1
Get Twitter RSS Feed_2.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/Change Server 2012 type.ps1
Change Server 2012 type.ps1
<# .SYNOPSIS Use this script to change Windows Server 2012 to 1 of 4 types. The script installs or uninstalls windows features to get to the desired type. The 4 types are: Core - just a commandline Minimal - commandline with added binaries to run some MMCs and Server Manager Full GUI - standard desktop look wit...
PowerShellCorpus/PoshCode/after.ps1
after.ps1
Get-WmiObject -Class Win32_MountPoint | where {$_.Directory -like ‘Win32_Directory.Name="D:\\\\MDBDATA*"’} | foreach { $vol = $_.Volume Get-WmiObject -Class Win32_Volume | where {$_.__RELPATH -eq $vol} | Select @{Name="Folder"; Expression={$_.Caption}}, @{Name="Server"; Expression={$_.SystemNa...
PowerShellCorpus/PoshCode/Import-CmdEnvironment_2.ps1
Import-CmdEnvironment_2.ps1
# .SYNOPSIS # Import environment variables from cmd to PowerShell # .DESCRIPTION # Invoke the specified command (with parameters) in cmd.exe, and import any environment variable changes back to PowerShell # .EXAMPLE # Import-CmdEnvironment ${Env:VS90COMNTOOLS}\\vsvars32.bat x86 # # Imports the x86 Visual Studio ...
PowerShellCorpus/PoshCode/ConvertTo-PseudoType.ps1
ConvertTo-PseudoType.ps1
function ConvertTo-PseudoType { <# .Synopsis Converts objects to custom PSObjects with robust type support .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 scripts) .P...
PowerShellCorpus/PoshCode/FTP upload_4.ps1
FTP upload_4.ps1
@charset "utf-8"; /* Credit: http://www.templatemo.com */ body { margin: 0px; padding: 0px; color: #c2bead; font-family: Tahoma, Geneva, sans-serif; font-size: 12px; line-height: 1.5em; background-color: #2f2e28; background-image: url(images/templatemo_body.jpg); background-repeat: repeat-y; ...
PowerShellCorpus/PoshCode/New-SQLComputerLogin_2.ps1
New-SQLComputerLogin_2.ps1
# Depends on Invoke-SQLCmd2 http://poshcode.org/2950 # Depends on Get-ADComputer http://poshcode.org/3011 function New-SqlComputerLogin { #.Synopsis # Creates a Login on the specified SQL server for a computer account #.Example # New-SqlComputerLogin -SQL DevDB2 -Computer BuildBox2 -Force # # Specifying the...
PowerShellCorpus/PoshCode/New-PemFile.ps1
New-PemFile.ps1
function New-PemFile { <# .SYNOPSIS Creates a new PEM file from one or more certificate files. .DESCRIPTION The New-PemFile function creates a new PEM file by using the content from certificate files. CER, CRT, and KEY files are the most common certificate file types. .PARAMETER Path The path or ...
PowerShellCorpus/PoshCode/Get-RandomNames.ps1
Get-RandomNames.ps1
function Get-RandomNames { <# .SYNOPSIS Gets Full Names from a List of Names from http://names.mongabay.com .DESCRIPTION Downloads the Names from the Websites and randomizes the order of Names and gives back an Object with surname, lastname and gender .PARAMETER MaxNames Number of names returned by the function ...
PowerShellCorpus/PoshCode/3f43dbaf-2e5c-4f5c-a244-776641571a20.ps1
3f43dbaf-2e5c-4f5c-a244-776641571a20.ps1
function Get-RandomNames { <# .SYNOPSIS Gets Full Names from a List of Names from http://names.mongabay.com .DESCRIPTION Downloads the Names from the Websites and randomizes the order of Names and gives back an Object with surname, lastname and gender .PARAMETER MaxNames Number of names returned by the function ...
PowerShellCorpus/PoshCode/6b9bb97b-5f9c-4504-af73-6d26a0372e0c.ps1
6b9bb97b-5f9c-4504-af73-6d26a0372e0c.ps1
Function Get-Printers { <# .SYNOPSIS Get a list of printers from the specified print server .DESCRIPTION This function returns the Name of each printer installed on the specified print server. .PARAMETER ComputerName Name of the print server .EXAMPLE ...
PowerShellCorpus/PoshCode/Enable_Configure SNMP_2.ps1
Enable_Configure SNMP_2.ps1
#Powershell Script To Install SNMP Services (SNMP Service, SNMP WMI Provider) #Variables :) $pmanagers = "ADD YOUR MANAGER(s)" $commstring = "ADD YOUR COMM STRING" #Import ServerManger Module Import-Module ServerManager #Check If SNMP Services Are Already Installed $check = Get-WindowsFeature | Where-Objec...
PowerShellCorpus/PoshCode/Get-LogicalDiskInfo_1.ps1
Get-LogicalDiskInfo_1.ps1
# ======================================================================== # # NAME: Get-LogicalDiskInfo.ps1 # # AUTHOR: Alex Ocampo , Daptiv Solutions LLC # DATE : 7/19/2011 # # COMMENT: Using WMI, script check logical disk information of a single # server or a group of servers. Script send email notificat...
PowerShellCorpus/PoshCode/More PSDrives.ps1
More PSDrives.ps1
function Mount-UserDrives { <# .Synopsis Create additional user drives. .Description To remove drives created with this function use Remove-UserDrives. .Link New-PSDrive Remove-UserDrives #> [Enum]::GetNames([Environment+SpecialFolder]) | % { New-PSDrive ...
PowerShellCorpus/PoshCode/AD-PromiscDetect.ps1
AD-PromiscDetect.ps1
<#================================================================================================ NAME: AD-PromiscDetect.ps1 AUTHOR: Marty J. Piccinich DATE CREATED: 9/15/2009 VERSION: 1.1 HISTORY: 1.0 9/15/2009 - Created 1.1 10/23/2009 - Added comment head...
PowerShellCorpus/PoshCode/Get-Parameter 2.7.ps1
Get-Parameter 2.7.ps1
#Requires -version 2.0 #.Synopsis # Enumerates the parameters of one or more commands #.Notes # With many thanks to Hal Rottenberg, Oisin Grehan and Shay Levy # Version 0.80 - April 2008 - By Hal Rottenberg http://poshcode.org/186 # Version 0.81 - May 2008 - By Hal Rottenberg http://poshcode.org/255 # Ver...
PowerShellCorpus/PoshCode/Test-Port_1.ps1
Test-Port_1.ps1
param ($ComputerName,$Port) $sock = new-object System.Net.Sockets.Socket -ArgumentList $([System.Net.Sockets.AddressFamily]::InterNetwork),$([System.Net.Sockets.SocketType]::Stream),$([System.Net.Sockets.ProtocolType]::Tcp) try { $sock.Connect($ComputerName,$Port) $sock.Connected $sock.Close() }...
PowerShellCorpus/PoshCode/Set-Prompt_2.ps1
Set-Prompt_2.ps1
#.Synopsis # Sets my favorite prompt function #.Notes # I put the id in my prompt because it's very, very useful. # # Invoke-History and my Expand-Alias and Get-PerformanceHistory all take command history IDs # Also, you can tab-complete with "#<id>[Tab]" so . # For example, the following commands: # r 4 ...
PowerShellCorpus/PoshCode/Get-FileEncoding_3.ps1
Get-FileEncoding_3.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/ADFS troubleshooting.ps1
ADFS troubleshooting.ps1
<# This Script will check the MSOnline Office 365 setup. It will prompt the user running it to specify the credentials. It will then check compare the onsite information with the online information and inform the user if it is out of sync. #> $PSAdmin = Read-host "This script needs to be run as Administrator,...
PowerShellCorpus/PoshCode/Get-EasterWestern.ps1
Get-EasterWestern.ps1
function Get-EasterWestern { Param( [Parameter(Mandatory=$true)] [int] $Year ) $a = $Year % 19 $b = [Math]::Floor($Year / 100) $c = $Year % 100 $d = [Math]::Floor($b / 4) $e = $b % 4 $f = [Math]::Floor(($b + 8) / 25) $g = [Math]::Floor((($b - $f + 1) / 3)) $h = ((19 ...
PowerShellCorpus/PoshCode/Test-Prompt.ps1
Test-Prompt.ps1
$choices = [System.Management.Automation.Host.ChoiceDescription[]](\n(new System.Management.Automation.Host.ChoiceDescription "&Yes","Choose me!"),\n(new System.Management.Automation.Host.ChoiceDescription "&No","Pick me!"))\n\n$Answer = $host.ui.PromptForChoice('Caption',"Message",$choices,(1))\n\nWrite-Output $Answer...
PowerShellCorpus/PoshCode/1dee8949-c4c9-4c6b-8530-45a36de22fdd.ps1
1dee8949-c4c9-4c6b-8530-45a36de22fdd.ps1
# For TabExpansion.ps1 # this requires latest TabExpansion.ps1 function Get-PipeLineObject { $i = -2 $property = $null do { $str = $line.Split("|") # extract the command name from the string # first split the string into statements and pipeline elements # This do...
PowerShellCorpus/PoshCode/LibraryInvocation.ps1
LibraryInvocation.ps1
## From Windows PowerShell Cookbook (O'Reilly)\n## by Lee Holmes (http://www.leeholmes.com/guide)\n\nSet-StrictMode -Version Latest\n\n## Return the name of the currently executing script\n## By placing this in a function, we drastically simplify\n## the logic it takes to determine the currently running\n## script\n\nf...
PowerShellCorpus/PoshCode/Beginner event 10 _1.ps1
Beginner event 10 _1.ps1
# # Summer 2009 Scripting games # Beginner Event 10 - The 1,500-Meter race # http://blogs.technet.com/heyscriptingguy/archive/2009/06/18/hey-scripting-guy-2009-scripting-games-event-10-details-beginner-and-advanced-1-500-meter-race.aspx # # ToDo: In this event, you must write a script that will count down from th...
PowerShellCorpus/PoshCode/Get-Hostname.ps1
Get-Hostname.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/Export-WLANSettings_1.ps1
Export-WLANSettings_1.ps1
# ============================================================================================== # # # NAME: Export-WLANSettings.ps1 # # AUTHOR: Jan Egil Ring # # DATE : 14.03.2010 # # COMMENT: Using netsh.exe to loop through each WLAN on the system and export the settings to the user-provided ...
PowerShellCorpus/PoshCode/POC $psnull.ps1
POC $psnull.ps1
$a = @" using System; namespace ClassLibrary1 { #proof of concept public static class Class1 { public static string Foo(string value) { if (value == null) return "Special processing of null."; else return "'" + value + "' has been processed."; } } } "@ $b = @" using System; namespace test...
PowerShellCorpus/PoshCode/New-Zip_5.ps1
New-Zip_5.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/Add-Namespace_1.ps1
Add-Namespace_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/Enable-BreakOnError.ps1
Enable-BreakOnError.ps1
#############################################################################\n##\n## Enable-BreakOnError\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\nCreat...
PowerShellCorpus/PoshCode/Deleted-ObjectsAD.ps1
Deleted-ObjectsAD.ps1
param( $Domen ) 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[]]$Info [string[]]$Computers ...
PowerShellCorpus/PoshCode/Get-Netstat 1,2.ps1
Get-Netstat 1,2.ps1
$null, $null, $null, $null, $netstat = netstat -a -n -o $ps = Get-Process [regex]$regexTCP = '(?<Protocol>\\S+)\\s+((?<LAddress>(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?))|(?<LAddress>\\[?[0-9a-fA-f]{0,4}(\\:([0-9a-fA-f]{0,...
PowerShellCorpus/PoshCode/Findup_1.ps1
Findup_1.ps1
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; using System.Runtime.InteropServices; using Microsoft.Win32; using System.IO; namespace Findup { public class FileInfoExt { public FileInfo...
PowerShellCorpus/PoshCode/chkhash_25.ps1
chkhash_25.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/ISE-CopyOutPutToEditor.ps1
ISE-CopyOutPutToEditor.ps1
function ISE-CopyOutPutToEditor () { $count = $psise.CurrentOpenedRunspace.OpenedFiles.count $psIse.CurrentOpenedRunspace.OpenedFiles.Add() $Newfile = $psIse.CurrentOpenedRunspace.OpenedFiles[$count] $Newfile.Editor.Text = $psIse.CurrentOpenedRunspace.output.Text $Newfile.Editor.Focus() # ...
PowerShellCorpus/PoshCode/Invoke-SqlCmd_8.ps1
Invoke-SqlCmd_8.ps1
####################### <# .SYNOPSIS Runs a T-SQL script. .DESCRIPTION Runs a T-SQL script. Invoke-Sqlcmd2 only returns message output, such as the output of PRINT statements when -verbose parameter is specified. Paramaterized queries are supported. .INPUTS None You cannot pipe objects to Invoke-Sq...
PowerShellCorpus/PoshCode/SVMotion-VM.ps1
SVMotion-VM.ps1
# author: Hal Rottenberg # Website/OpenID: http://halr9000.com # purpose: does "real" SVMotion of a VM # usage: get-vm | SVMotion-VM -destination (get-datastore foo) function SVMotion-VM { param( [VMware.VimAutomation.Client20.DatastoreImpl] $destination ) Begin { $datastoreView = get-view $destina...