Skip to content

Instantly share code, notes, and snippets.

View 1RedOne's full-sized avatar

Stephen Owen 1RedOne

View GitHub Profile
<#
.Synopsis
Modifies the web.config file for all servers for specific SharePoint web application.
.Description
Modifies the web.config file for all servers for specific SharePoint web application.
.Example
Add-SPCORSOrigin -Url http://domain.com
@1RedOne
1RedOne / July 2015 PowerShell challenge
Last active August 29, 2015 14:24
PowerShell Puzzles
<#
Write a one-liner that produces the following output (note that property values will be different from computer to computer; that’s fine).
PSComputerName ServicePackMajorVersion Version· BIOSSerial
-------------- ----------------------- -------· ----------
win81· · · · · · · · · · · · · · · · 0 6.3.9600 VMware-56 4d 09 1 71 dd a9 d0 e6 46 9f
By definition, a one-liner is a single, long command or pipeline that you type, hitting Enter only at the very end. If it wraps to more than one physical line as you’re typing, that’s OK. But, in order to really test your skill with the parser, try to make your one-liner as short as technically possible while still running correctly.
#>
@1RedOne
1RedOne / TestScript.ps1
Created December 2, 2015 15:46
StackOverFlow - Multiple switch values inside a loop
#Make a few test files
290..296 | %{
"ham" > t:\"ham$($_)bacon.iso"}
#verify they were created
dir t:\*.iso
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 12/2/2015 10:41 AM 12 ham290bacon.iso
@1RedOne
1RedOne / Popup.ps1
Created December 3, 2015 15:18
PowerShell XAML Popup with customizable buttons
#ERASE ALL THIS AND PUT XAML BELOW between the @" "@
$inputXML = @"
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="Window Title goes here" Height="350" Width="525">
@1RedOne
1RedOne / Adding IP Address to script output
Created December 8, 2015 16:44
Helping someone on StackExchange
$computername = 'localhost', $env:COMPUTERNAME
foreach ($Computer in $ComputerName) {
try {
quser /server:$Computer 2>&1 | Select-Object -Skip 1 | ForEach-Object {
$CurrentLine = $_.Trim() -Replace '\s+',' ' -Split '\s'
$HashProps = @{
UserName = $CurrentLine[0]
ComputerName = $Computer
}
@1RedOne
1RedOne / Get-ACLSpreadSheet.ps1
Created December 18, 2015 20:20
Get-ACLs for a list of folders, writing out to an Excel sheet
$ErrorActionPreference = "Stop"
$Excel = new-Object -comobject Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Cells.Item(1,1) = "Folder Name"
$Sheet.Cells.Item(1,2) = "Folder Permissions (allow)"
$Sheet.Cells.Item(1,3) = "Folder Permissions (Deny)"
$intRow = 2
#oh man, everyone elses were so much better, this is embarassing...
#v3
$folder = 0
$pgnFiles = 'X:\ChessData-master\ChessData-master'
$blacktot=$whitetot=$null
$blacktot = new-object System.Collections.ArrayList
$whitetot = new-object System.Collections.ArrayList
$draw = new-object System.Collections.ArrayList
@1RedOne
1RedOne / MakemeaHashtable.ps1
Created March 22, 2016 14:43
PowerShell objects are tricky
$Body = @"
[{
"action": "EventsRouter",
"method": "query",
"data": [{
"uid": "/zport/dmd/",
"params": {
"eventState": [0, 1],
"severity": [5, 4, 3, 2],
"excludeNonActionables": false
@1RedOne
1RedOne / Get-SCOMURVersion
Created April 6, 2016 15:42
SCOM - Get Update Rollup Version
#Sick of manually tracking down the SCOM Update Rollup version? Me too! Run this on a management server to get the Update Rollup version
#Find SCOM install path
$SCOMDirectory = get-childitem -Recurse c:\*\Console | ? PSIsContainer | select -First 1
$SCOMDll = (get-item $SCOMDirectory\Microsoft.EnterpriseManagement.UI.Authoring.dll).VersionInfo.FileVersion
switch ($SCOMDll)
{
'7.0.9538.0' {'SCOM 2012 SP1 RTM'}
'7.0.9538.1005' {'SCOM 2012 SP1 UR1'}
@1RedOne
1RedOne / Weather.ps1
Created May 6, 2016 15:52
Get-Weather
Function Get-Weather {
$city = "33.9533,-84.5406"
#sign up for an API key here https://developer.forecast.io/
$APIkey = "$null"
$url = "https://api.forecast.io/forecast/$APIkey/$city"
try{$weather = Invoke-WebRequest $url -ea STOP|ConvertFrom-Json }
catch{write-host -ForegroundColor Yellow "We don't seem to have internet access"
break}