This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-VMHost | Where-Object { $_.ConnectionState -eq “Connected” } | Foreach-Object { | |
$CurrentVMhost = $_ | |
TRY | |
{ | |
# Exposes the ESX CLI functionality of the current host | |
$ESXCLI = Get-EsxCli -VMHost $CurrentVMhost.name | |
# Retrieve Vib with name 'net-e1000e' | |
$ESXCLI.software.vib.list() | Where-object { $_.Name -eq "net-e1000e" } | | |
FOREACH | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Source: Reddit (http://www.reddit.com/r/PowerShell/comments/2oqk4k/using_validateset_with_exceptions/) | |
function test { | |
# You have to use cmdletbinding for the dynamic parameter to work | |
[CmdletBinding()] | |
Param() | |
# The cool thing about this is that you can actually get really good tab completion / intellisense from doing it this way... | |
DynamicParam | |
{ | |
[string[]]$ValidServices = get-content $PSScriptRoot\services.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Technique one: COM Object Version | |
$s = New-Object -ComObject SAPI.SPVoice | |
$s.Speak("You are Re-Hired!") | |
# Technique two: NET Object Version | |
Add-Type -AssemblyName System.speech | |
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer | |
# Play a sound | |
$speak.Speak("Pomme de terre") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-Uptime | |
{ | |
$millisec = [Environment]::TickCount | |
[Timespan]::FromMilliseconds($millisec) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ForEach-Parallel | |
{ | |
<# | |
.DESCRIPTION | |
.SYNOPSIS | |
.NOTES | |
Source: http://powertoe.wordpress.com/2012/05/03/foreach-parallel/ | |
.EXAMPLE | |
(0..50) |ForEach-Parallel -MaxThreads 4{ | |
$_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"::1" -as [ipaddress] | fl * -Force | |
IPAddressToString : ::1 | |
Address : | |
AddressFamily : InterNetworkV6 | |
ScopeId : 0 | |
IsIPv6Multicast : False | |
IsIPv6LinkLocal : False | |
IsIPv6SiteLocal : False | |
IsIPv6Teredo : False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Jeff Hicks | |
# http://www.petri.com/creating-advance-functions-powershell.htm?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Petri+%28Petri+IT+Knowledgebase%29 | |
Function Get-MyUptime { | |
[cmdletbinding()] | |
Param( | |
[Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)] | |
[ValidateNotNullorEmpty()] | |
[Alias("cn","host")] | |
[string[]]$Computername = $env:Computername |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Credit: SAPIEN | |
function ConvertTo-DataTable | |
{ | |
<# | |
.SYNOPSIS | |
Converts objects into a DataTable. | |
.DESCRIPTION | |
Converts objects into a DataTable, which are used for DataBinding. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Connect-PerforceServer | |
{ | |
<# | |
.SYNOPSIS | |
Connect to a Perforce Server | |
.DESCRIPTION | |
Connect to a Perforce Server | |
#> | |
[CmdletBinding()] | |
PARAM( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Show-OpenFileDialog | |
{ | |
param | |
($Title = 'Pick a File', $Filter = 'All|*.*|PowerShell|*.ps1') | |
$type = 'Microsoft.Win32.OpenFileDialog' | |
$dialog = New-Object -TypeName $type | |
$dialog.Title = $Title |