Skip to content

Instantly share code, notes, and snippets.

View lazywinadmin's full-sized avatar

François-Xavier Cat lazywinadmin

View GitHub Profile
@lazywinadmin
lazywinadmin / Vmware_Hosts_VIB.ps1
Last active August 29, 2015 14:10
Get the VIB information of VMware Hosts
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
{
#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
@lazywinadmin
lazywinadmin / PowerShellVoice.ps1
Created December 10, 2014 21:20
Show how to use the Speech feature in Windows using PowerShell
# 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")
@lazywinadmin
lazywinadmin / Get-Uptime.ps1
Created December 12, 2014 15:43
Smart way to get the uptime on a local machine
function Get-Uptime
{
$millisec = [Environment]::TickCount
[Timespan]::FromMilliseconds($millisec)
}
@lazywinadmin
lazywinadmin / ForEach-Parallel.ps1
Created December 22, 2014 23:51
Execute parallel powershell thread using runspace objects
function ForEach-Parallel
{
<#
.DESCRIPTION
.SYNOPSIS
.NOTES
Source: http://powertoe.wordpress.com/2012/05/03/foreach-parallel/
.EXAMPLE
(0..50) |ForEach-Parallel -MaxThreads 4{
$_
@lazywinadmin
lazywinadmin / [Ipaddress].ps1
Last active August 29, 2015 14:12
Smart way to convert string to ipaddress data
"::1" -as [ipaddress] | fl * -Force
IPAddressToString : ::1
Address :
AddressFamily : InterNetworkV6
ScopeId : 0
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
@lazywinadmin
lazywinadmin / Get-MyUptime.ps1
Created December 30, 2014 18:21
Get Uptime of remote computers
# 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
#Credit: SAPIEN
function ConvertTo-DataTable
{
<#
.SYNOPSIS
Converts objects into a DataTable.
.DESCRIPTION
Converts objects into a DataTable, which are used for DataBinding.
@lazywinadmin
lazywinadmin / Connect_and_Create_Perforce_User.ps1
Last active August 29, 2015 14:14
Create perforce user using powershell
function Connect-PerforceServer
{
<#
.SYNOPSIS
Connect to a Perforce Server
.DESCRIPTION
Connect to a Perforce Server
#>
[CmdletBinding()]
PARAM(
function Show-OpenFileDialog
{
param
($Title = 'Pick a File', $Filter = 'All|*.*|PowerShell|*.ps1')
$type = 'Microsoft.Win32.OpenFileDialog'
$dialog = New-Object -TypeName $type
$dialog.Title = $Title