Skip to content

Instantly share code, notes, and snippets.

@OlafD
OlafD / ConnectExchangeOnline.ps1
Last active January 11, 2024 12:51
Connect to Office 365 Exchange Online with PowerShell
if ($cred -eq $null)
{
$cred = Get-Credential
}
Write-Host "Connecting to Exchange Online"
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $exchangeSession | Out-Null
@OlafD
OlafD / GetInstalledApps.ps1
Last active October 5, 2018 07:34
Show all installed apps from the app catalog for a SharePoint site. The script just provides a simple output of the AppTile class. The script needs the PowerShell PnP extensions installed.
param (
[string]$Url,
$Credentials
)
if ($Credentials -eq $null)
{
$Credentials = Get-Credential
}
@OlafD
OlafD / GetGroupOwners.ps1
Created October 5, 2018 10:07
Get all the assigned owners of an Office 365 Groups group, also getting the owners in a Teams team. The script connects to Exchange Online to get the information.
param (
[string]$GroupName,
$Credentials
)
if ($Credentials -eq $null)
{
$Credentials = Get-Credential
}
@OlafD
OlafD / Deploy-WebApp.ps1
Created October 8, 2018 06:32
Deploy a package for an Azure Web App, generated in Visual Studio, to Azure.
param (
[Parameter(Mandatory=$true)]
[string]$PublishSettingsFile,
[Parameter(Mandatory=$true)]
[string]$DeploymentBatch,
[Parameter(Mandatory=$true)]
[string]$WebAppUrl,
[switch]$Deploy
)
@OlafD
OlafD / LoopAllSubwebs-EmptyScript.ps1
Last active November 28, 2018 15:25
The starting point for a PowerShell script that loops all sites of a site collection to perform any function. The function(s) could be inserted starting in line 27. The script will write a transcript, the filename could be modified in line 51.
param (
[Parameter(Mandatory=$true)]
[string]$Url,
[Parameter(Mandatory=$true)]
[string]$TranscriptPath,
[Parameter(Mandatory=$true)]
$Credentials,
[switch]$IgnoreRoot
)
@OlafD
OlafD / GetGroupOwnership.ps1
Last active October 11, 2018 09:36
For Office 365 get information about the ownership for Office 365 groups of a user, given by the mail address. Using this script needs the cmdlets for AzureAD (https://docs.microsoft.com/de-de/azure/active-directory/users-groups-roles/groups-settings-v2-cmdlets).
param (
[string]$UserMail
)
function Ensure-AzureADConnection
{
try
{
# $var = Get-AzureADTenantDetail
$var = Get-AzureADUser -Top 1
@OlafD
OlafD / Transcript-Example-Program.cs
Last active October 23, 2018 10:21
A simple class to create transcript files for console applications. The filename for the transcript could be constructed by the constructor of the class to have the current date in the filename. Additionally an example for the usage.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TranscriptTester
{
class Program
{
@OlafD
OlafD / ShowImageInPopupDialog.txt
Last active November 28, 2018 16:17
Snippet for a SharePoint Script Editor webpart, to show an image and on a click show the image
<script type="text/javascript">
var dlgOptions;
function setDlgOptions(pictureUrl) {
var htmlFragment = document.createElement("img");
htmlFragment.setAttribute("src", pictureUrl);
htmlFragment.setAttribute("width", "800");
htmlFragment.setAttribute("height", "600");
@OlafD
OlafD / RestAgainstSharePointOnline.ps1
Last active January 21, 2019 14:22
From the PowerShell PnP extensions installed on any machine, copy the files Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll to the same folder, as this script. Then, you can execute a Rest call like .\RestAgainstSharePointOnline.ps1 -Url https://{yourtenant}.sharepoint.com/_api/web -UserName {youruser} -Password {your…
param (
[string]$Url,
[string]$UserName,
[string]$Password,
[Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get
)
$currentPath = (Get-Item -Path ".\").FullName
Add-Type -Path "$currentPath\Microsoft.SharePoint.Client.dll"
@OlafD
OlafD / AddChoiceToChoiceField.ps1
Created January 8, 2019 13:57
In SharePoint Online, add a new choice value to an existing choice field. The fieldname in the example is "MyChoiceField" with 3 very simple choices. A fourth choice is added by the script. A connection to the SharePoint site must be established.
$field = Get-PnPField -Identity "MyChoiceField"
$ctx = Get-PnPContext
$fieldChoice = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.FieldChoice]).Invoke($ctx, $field)
$ctx.Load($fieldChoice)
Invoke-PnPQuery