Skip to content

Instantly share code, notes, and snippets.

@ciphertxt
ciphertxt / Test-SPContentDatabaseToCSV.ps1
Created November 12, 2015 15:03
Runs Test-SPContentDatabase against all web applications/content databases and outputs to a CSV. From http://blogs.technet.com/b/fromthefield/archive/2013/07/29/automating-test-spcontentdatabase.aspx
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
foreach ($WebApp in (Get-SPWebApplication)) {
"Testing Web Application - " + $WebApp.Name | Write-Host -ForegroundColor Green;
foreach ($CDB in $WebApp.ContentDatabases) {
Test-SPContentDatabase -Name $CDB.Name -WebApplication $WebApp.URL -ServerInstance $CDB.Server | ConvertTo-Csv | Out-File -Encoding default -FilePath $("C:\temp\" + $CDB.Name + ".csv")
}
}
@ciphertxt
ciphertxt / SetSPUIVersion.ps1
Created March 26, 2013 11:47
Sets the UIVersion to v3 or v4 for all sites in a given database
function Set-SPUIVersion(
    [string]$dbName = $(Read-Host -prompt "Content Database Name"),
    [int32]$uiVersion = $(Read-Host -prompt "UI Version"))
    {
    $db = Get-SPContentDatabase $dbName
 
    foreach ($s in $db.Sites) {
        foreach ($w in $s.AllWebs) {
            $w.UIversion = $uiVersion;
            switch ($uiVersion) {
@ciphertxt
ciphertxt / GetSPFarmSolutions.ps1
Created March 26, 2013 11:48
Saves all farm solutions to the specified directory
function Get-SPFarmSolutions {
    param (
        [string] $directory = $(Read-Host -prompt "Enter a directory (use ""."" for current dir)")
    )
 
    if ($directory.Length -lt 2) {
        $directory = [string]$pwd + "\\";
    }
 
    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local;
@ciphertxt
ciphertxt / PSConfig.cmd
Created March 26, 2013 11:49
PSConfig cmd line for after applying a patch
psconfig -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures
@ciphertxt
ciphertxt / PopulateUserInformationList.ps1
Created March 26, 2013 11:50
Adds all users in the UPA to a given site collection. Handy for pre-populating a User Information List
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# Enter your SharePoint site URL here...
$site = new-object Microsoft.SharePoint.SPSite("http://intranet");
$web = Get-SPWeb "http://intranet";
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);
@ciphertxt
ciphertxt / CreateUserProfile.ps1
Created March 26, 2013 11:50
Creates a new user profile in the UPA
Add-PSSnapin Microsoft.SharePoint.PowerShell
$siteUrl = "http://mycoolsite/"
$accountName = "MyAccountName"
$site = Get-SPSite $siteUrl
$context = Get-SPServiceContext($site)
$pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
# If user profile doesn't exist create new one
@ciphertxt
ciphertxt / BackupWebConfig.ps1
Created March 26, 2013 11:52
Backup the web.config for a given web application
$webappName = “http://intranet.contoso.com”
$backupDir = “C:\backups”
Write-Host "Backing up $webappName web.config file…" -foreground Gray –nonewline
## Get the web application – by display name
$w = Get-SPWebApplication | where { $_.DisplayName -eq "$webappName"}
## Get the default (first) zone for the web app…
## You may wish to iterate through all the available zones
########################################################################
# Connect to an Azure subscription
########################################################################
Login-AzureRmAccount
# Select your subscription if required
Select-AzureRmSubscription -SubscriptionId "yoursubscriptionid"
########################################################################
# Copy a Vhd from an existing storage account to a new storage account
#requires -Version 2 -Modules ActiveDirectory
Get-ADOrganizationalUnit -Filter * |
ForEach-Object {
$OU = $_
Get-ADComputer -Filter * -SearchBase $OU.DistinguishedName -SearchScope SubTree -Properties Enabled, OperatingSystem |
Where-Object { $_.Enabled -eq $true } |
Group-Object -Property OperatingSystem -NoElement |
@ciphertxt
ciphertxt / Get-MsolLicensedUsers.ps1
Last active January 11, 2016 14:45
Gets a collection of licensed users from O365 tenant and exports to a CSV
Get-MsolUser -All | Where-Object { $_.isLicensed -eq "TRUE" } | Select-Object UserPrincipalName, DisplayName, Country, Department -ExpandProperty Licenses | Export-Csv c:\LicensedUsers.csv