Skip to content

Instantly share code, notes, and snippets.

@jonschoning
jonschoning / TypeHelpers.ps1
Created August 16, 2011 14:33
TypeHelpers.ps1
function Get-Type() { [AppDomain]::CurrentDomain.GetAssemblies() | % { $_.GetTypes() }}
function Get-MSDNInfo([Type]$t) { (New-Object –com Shell.Application).Open(“http://msdn.microsoft.com/$(Get-Culture)/library/$($t.FullName).aspx” ) }
function Show-ClassInfo([Type]$t) { Get-Member –input (New-Object $t.FullName $args) | Out-Gridview}
@jonschoning
jonschoning / SP2010_PS_Examples.ps1
Created August 16, 2011 14:36
SP2010_PS_Examples.ps1
# %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\Config\PowerShell\Registration\SharePoint.ps1
# $Host.Runspace.ThreadOptions = "ReuseThread"
# Add-PsSnapin Microsoft.SharePoint.PowerShell
#DEMO: Get-Command, Get-Member
#Display the help for the Get-Command cmdlet
help get-command
#Get a listing of all the SharePoint cmdlets
@jonschoning
jonschoning / Visit-AllFiles.ps1
Created August 16, 2011 14:36
Visit-AllFiles.ps1
# Calling Excel Math Functions From PowerShell
$xl = New-Object -ComObject Excel.Application
$xlprocess = Get-Process excel
$worksheet_function = $xl.WorksheetFunction
$data = 1,2,3,4
$matrix = ((1,2,3),(4,5,6),(7,8,10))
Write-Host -ForegroundColor green Median
@jonschoning
jonschoning / ExcelMathPowerShell.ps1
Created August 16, 2011 14:38
ExcelMathPowerShell.ps1
# Calling Excel Math Functions From PowerShell
$xl = New-Object -ComObject Excel.Application
$xlprocess = Get-Process excel
$wf = $xl.WorksheetFunction
$data = 1,2,3,4
$m = ((1,2,3),(4,5,6),(7,8,10))
Write-Host -ForegroundColor green Median
@jonschoning
jonschoning / Get-NetworkStatus.ps1
Created August 16, 2011 14:46
Get-NetworkStatus.ps1
function Get-NetworkStatus {
$t = [Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")
$networkListManager = [Activator]::CreateInstance($t)
$connections = $networkListManager.GetNetworkConnections()
function getconnectivity {
param($network)
switch ($network.GetConnectivity()) {
0x0000 { 'disconnected' }
{ $_ -band 0x0001 } { 'IPV4_NOTRAFFIC' }
{ $_ -band 0x0002 } { 'IPV6_NOTRAFFIC' }
@jonschoning
jonschoning / Get-SubDirSizes.ps1
Created August 16, 2011 14:48
Get-SubDirSizes.ps1
function Get-SubDirSizes {
param([Parameter(Mandatory=$true)] [string] $path)
dir $path -force |
? { $_.PSIsContainer} |
% { new-object PsObject -property @{
Length = (dir $_.FullName -recurse -force | ? {! $_.PSIsContainer} | measure-object -sum Length).Sum;
Name = $_.Name
}
} |
@jonschoning
jonschoning / Format-Columns.ps1
Created August 16, 2011 14:53
Format-Columns.ps1
function Format-Columns {
################################################################
#.Synopsis
# Formats incoming data to columns.
#.Description
# It works similarly as Format-Wide but it works vertically. Format-Wide outputs
# the data row by row, but Format-Columns outputs them column by column.
#.Parameter Property
# Name of property to get from the object.
# It may be
@jonschoning
jonschoning / regex.bas
Created August 16, 2011 21:30
regex.bas
Attribute VB_Name = "Module1"
Function RegexMatch(Value As String, Pattern As String, Optional IgnoreCase As Boolean = False)
Dim r As New VBScript_RegExp_55.RegExp
r.Pattern = Pattern
r.IgnoreCase = IgnoreCase
RegexMatch = r.Test(Value)
End Function
Function RegexReplace(Value As String, Pattern As String, ReplaceWith As String, Optional IgnoreCase As Boolean = False)
Dim r As New VBScript_RegExp_55.RegExp
@jonschoning
jonschoning / SP.ps1
Created August 29, 2011 17:48
SP.ps1
param($startstop)
if($startstop.ToLower() -eq "stop")
{
IISRESET /STOP
gsv | ? {$_.DisplayName -like "*share*"} | set-service -StartupType Manual
gsv | ? {$_.DisplayName -like "*share*"} | spsv -force
gsv | ? {$_.DisplayName -like "*World Wide Web*"} | set-service -StartupType Manual
gsv | ? {$_.DisplayName -like "*World Wide Web*"} | spsv
@jonschoning
jonschoning / SelectionMultipliers.bas
Created August 30, 2011 15:12
SelectionMultipliers.bas
Attribute VB_Name = "Module1"
Sub DblVals()
Attribute DblVals.VB_ProcData.VB_Invoke_Func = "D\n14"
Dim cell As Range
For Each cell In Selection
If (cell.Value > 0) Then
cell.Value = (cell.Value * 2#)
End If
Next
End Sub