Skip to content

Instantly share code, notes, and snippets.

$cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
@ciphertxt
ciphertxt / GetEnterprisePackStatus.ps1
Last active March 18, 2016 15:29
Retrieves a list of users with an ENTERPRISEPACK assignment and outputs the ProvisioningStatus of the Service Plans associated with the enterprise pack.
Import-Module MSOnline -EA 0
$credential = Get-Credential
Connect-MsolService -Credential $credential
$accountSKU = Get-MsolAccountSku | ? { $_.AccountSKUID -like "*ENTERPRISEPACK" }
$users = Get-MsolUser -All | Where-Object { $_.isLicensed -eq "TRUE" } | Select-Object UserPrincipalName, DisplayName, Country, Department -ExpandProperty Licenses | ? { $_.AccountSKUID -eq $accountSKU.AccountSkuID }
@ciphertxt
ciphertxt / GetOD4BSites.ps1
Created January 25, 2016 20:21
How to display a list of OneDrive for Business site collections https://technet.microsoft.com/en-us/library/dn911464.aspx
# Specifies the URL for your organization's SPO admin service
$AdminURI = "https://tenantname-admin.sharepoint.com"
# Specifies the User account for an Office 365 global admin in your organization
$AdminAccount = ""
$AdminPass = ""
# Specifies the location where the list of MySites should be saved
$LogFile = "~\Desktop\MySites.txt"
@ciphertxt
ciphertxt / FormsSignIn.aspx.cs
Last active January 25, 2016 17:45
Updates an AD FS 2.0 Login page (FormsSignin.aspx) to autopopulate the user name and set the password focus. * http://mikepfeiffer.net/2012/05/useful-cutomizations-to-ad-fs-2-0-when-deploying-sso-with-office-365/ * https://msdn.microsoft.com/en-us/library/ee895357.aspx
protected void Page_Load( object sender, EventArgs e )
{
if (!this.IsPostBack)
{
// Extract the username fromt he query string and set the username TextBox
string url = Context.Request.Url.AbsoluteUri;
System.Collections.Specialized.NameValueCollection parameters = System.Web.HttpUtilitiy.ParseQueryString(url);
string userName = parameters["username"];
if (!String.IsNullOrEmpty(userName))
#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 |
########################################################################
# 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
@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
@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")
}
}
with fs
as
(
select database_id, type, size * 8.0 / 1024 size
from sys.master_files
)
select
name,
(select sum(size) from fs where type = 0 and fs.database_id = db.database_id) DataFileSizeMB,
(select sum(size) from fs where type = 1 and fs.database_id = db.database_id) LogFileSizeMB
@ciphertxt
ciphertxt / Get-SPDatabaseSizes.ps1
Created October 26, 2015 17:17
Gets the sizes and required storage of existing SharePoint databases. From http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=193
Get-SPDatabase | ForEach-Object {$db=0} {$db +=$_.disksizerequired; $_.name + " - " + $_.disksizerequired/1024/1024} {Write-Host "`nTotal Storage (in MB) =" ("{0:n0}" -f ($db/1024/1024))} | Out-File c:\temp\spdatabasesizes.txt