Skip to content

Instantly share code, notes, and snippets.

View sweeneyrobb's full-sized avatar

Robert Sweeney sweeneyrobb

View GitHub Profile
@sweeneyrobb
sweeneyrobb / Select-FileDialog.ps1
Last active December 22, 2015 17:09
a cool file select powershell script I found.
function Select-FileDialog
{
param([string]$Title, [string]$Directory, [string]$Filter="All Files (*.*)|*.*" )
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$objForm = New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory = $Directory
$objForm.Filter = $Filter
$objForm.Title = $Title
$Show = $objForm.ShowDialog()
if ($Show -eq "OK") {
@sweeneyrobb
sweeneyrobb / add-spadmin.ps1
Last active August 29, 2015 14:06
Easy way to add a user as an administrator. Grants Farm Administrator rights along with ShellAdmin for Central Administration and a specified url.
$username = "{username}"
$webAppUrl = "{url}"
$centralAdmin = Get-SPWebApplication -IncludeCentralAdministration | ?{$_.DisplayName -eq "SharePoint Central Administration v4"}
$caWeb = Get-SPWeb -Identity $centralAdmin.Url
$farmAdministrators = $caWeb.SiteGroups["Farm Administrators"]
$farmAdministrators.AddUser($username, "", $username, "Configured via PowerShell")
$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$settings = $service.DeveloperDashboardSettings
$settings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$settings.Update()
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function EnsureDirectory($exportFolderPath) {
if (-not (Test-Path $exportFolderPath)) {
New-Item $exportFolderPath -Type Directory | Out-Null
}
}
function ExportAllWebParts($siteUrl, $pageUrl, $exportFolderPath) {
$web = Get-SPWeb $siteUrl
@sweeneyrobb
sweeneyrobb / configure-teamcitybuildagent.ps1
Created September 4, 2014 19:47
Installs Chocolatey, MSBuild tools, Java runtimes (req for TC), Team City build agent, and SharePoint pre-requisites.
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco install microsoft-build-tools
choco install javaruntime
choco install TeamCityAgent -params 'serverurl=http://{teamcityurl}:8080 agentName=Agent1 agentDir=C:\\TeamCity\\buildAgent'
# installs sharepoint build dependancies. Review https://officesharepointci.codeplex.com/ for more information.
# should convert this to a chocolatey package too :)
.\OfficeSharePointCI\TfsBuildServerPrerequisites.ps1 -Install
@sweeneyrobb
sweeneyrobb / configure-machine.ps1
Last active June 10, 2019 07:04
This script is used to configure my developer desktop
Set-ExecutionPolicy -ExecutionPolicy Bypass -Force
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
cinst googlechrome -y
cinst slack -y
cinst vscode -y
cinst sql-server-management-studio -y
cinst firacode -y
@sweeneyrobb
sweeneyrobb / New-Zip.ps1
Created October 29, 2014 17:07
Creates a zip file and adds a file or directory
function New-Zip ( $zipFile, $file ) {
if ($file -is [string]) {
$file = Get-Item $file
}
set-content $zipFile ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
$zipFile = Get-Item $zipFile
$zipFile.IsReadOnly = $false
$zip = (New-Object -ComObject shell.application).NameSpace($zipFile.FullName)
function Extract-Zip ($zipFile, $directory = ".\") {
if ($directory -is [string]) {
$directory = Get-Item $directory }
if ($zipFile -is [string]) {
$zipFile = Get-Item $zipFile }
$zip = (New-Object -ComObject shell.application).NameSpace($zipFile.FullName)
$destination = (New-Object -ComObject shell.application).namespace($directory.FullName)
@sweeneyrobb
sweeneyrobb / remove-web-config-modifications.ps1
Created November 26, 2014 02:38
Will prompt for which web.config modification entries to remove from an SPWebApplication. Useful when developer forgets to create a retract handler.
$app = get-spwebapplication "http://{webapp_url}"
$mods = $app.WebConfigModifications
$mods.Remove(($mods | out-gridview -PassThru))
$app.Parent.Update()
$app.Parent.ApplyWebConfigModifications()
@sweeneyrobb
sweeneyrobb / jekyll-boilerplate.ps1
Created July 1, 2015 20:02
Creating a boilerplate Jekyll directory.
$folders = @("_drafts", "_includes", "_layouts", "_posts", "_data")
$folders | %{ New-Item -Name $_ -ItemType Directory }
$files = @("_config.yml")
$files | %{ New-Item -Name $_ -ItemType File }