Skip to content

Instantly share code, notes, and snippets.

View mardahl's full-sized avatar
🤓
not afraid to commit!

Michael Mardahl mardahl

🤓
not afraid to commit!
View GitHub Profile
@mardahl
mardahl / SudoFunction.ps1
Created August 5, 2018 23:55
Example of a SUDO function for powershell
function sudo
{
$file, [string]$arguments = $args;
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;
[System.Diagnostics.Process]::Start($psi);
}
#Simple script to change all Unified Groups (Office 365 Groups) Primaty SMTP email address to a new domain.
#It's recomended to have a diferent email domain for Office 365 Groups, so they dont conflict with regular user and system mailboxes.
$groups = get-unifiedgroup | select-object name,alias
Foreach ($group in $groups) {
Set-UnifiedGroup –Identity "$($group.name)" –PrimarySmtpAddress "$($group.alias)@groups.contoso.com"
}
@mardahl
mardahl / anon-redelegateDK
Created September 11, 2018 06:25
Script to send redelegation requests for multiple .dk domains to dkhostmaster - saving time typing them in manually.
$DomainNames = @(
'domA.dk',
'domB.dk'
)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Foreach ($Domain IN $DomainNames) {
@mardahl
mardahl / ps_map_drives.ps1
Created April 5, 2019 10:10
Network drive mapping via Intune
<#
.SYNOPSIS
This script will map network drives to a specified fileserver (ment to be used as an Intune PowerShell script)
.DESCRIPTION
The script will test the connection to the domain (via FQDN), in case it fails, there is an option to make it retry again one minute later.
If all fails, it will skip the mapping of the drives.
.EXAMPLE
Just run this script without any parameters in the logged in users context (as an Intune Extensions Powershell script).
.NOTES
NAME: ps_map_drives.ps1
@mardahl
mardahl / Outlk16.admx
Created October 28, 2018 21:02
Outlook 2016 ADMX Group Policy
<?xml version="1.0" encoding="utf-16"?>
<policyDefinitions revision="1.0" schemaVersion="1.0">
<policyNamespaces>
<target prefix="outlk16" namespace="outlk16.Office.Microsoft.Policies.Windows" />
<using prefix="windows" namespace="Microsoft.Policies.Windows" />
</policyNamespaces>
<supersededAdm fileName="outlk16" />
<resources minRequiredRevision="1.0" />
<categories>
<category name="L_MicrosoftOfficeOutlook" displayName="$(string.L_MicrosoftOfficeOutlook)" />
@mardahl
mardahl / PS-BGInfo.ps1
Created September 26, 2019 13:51 — forked from dieseltravis/PS-BGInfo.ps1
update wallpaper background image with powershell (like Sysinternals BGInfo)
# PS-BGInfo
# Powershell script that updates the background image with a random image from a folder and writes out system info text to it.
# run as a lower priority task
[System.Threading.Thread]::CurrentThread.Priority = 'BelowNormal'
# Configuration:
# Font Family name
$font="Input"
@mardahl
mardahl / ExternalUserAndGuestSharing.ps1
Last active May 5, 2020 12:57
Enable anyone links on Teams and Office365 groups
# As a default, sharing links with anyone is disabled on Office 365 groupSites, which in turn also means Microsoft Teams Sites.
# Even if you have Anyone sharing enabled at the tenant level!
# This script can help y remove that requirement from a specific site.
# MIT licensing, keep author credits if reusing
# Author: Michael Mardahl @michael_mardahl on twitter
# https://github.com/mardahl
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
ipmo Microsoft.Online.SharePoint.PowerShell
@mardahl
mardahl / restrict_Office365Groups_creation.ps1
Last active May 27, 2020 19:00
Script to restrict creation of Office365 Groups
<#
.DESCRIPTION
Quick and dirty script to limit the creation of Office 365 Group or Microsoft Teams (Teams) to a specific security group in Azure AD (or One Synced form on-prem AD)
#>
#security group that is allowed to create Office 365 Groups
$secGroup = "Teams Creation Administrators"
#importing AzureAD Module (should be installed!)
try {
Import-module AzureADPreview
@mardahl
mardahl / gist:b2a3b0f74e6fd73ab0878085ed1ecc70
Created July 25, 2020 14:41
Function to verify that a certificate by specific template exists, using powershell
function VerifyCertificateExists($issuer, $templateName){
#function that validates existence of required certificate.
#input issuer and template name (wildcards will automatically be added).
#example : VerifyCertificateExists -issuer "myCompany" -templateName "myCertTemplate"
#MIT license - github.com/mardahl
try {
Write-Verbose "Verifying existence of required certificate..." -Verbose
$certs = Get-ChildItem -Path cert:\currentuser\my | Where-Object Issuer -like "*$issuer*" -ErrorAction Stop
$cert = $certs | Where-Object{ $_.Extensions | Where-Object{ ($_.Oid.Value -eq '1.3.6.1.4.1.311.21.7') -and ($_.Format(0) -like "*$templateName*") }} -ErrorAction Stop
if(!$cert){throw}
@mardahl
mardahl / gist:8e22c5ca71f95cb616a45f0db36bc78c
Last active October 7, 2020 12:26
Create exchange send connector for relaying through exchange online protection
#This script will create a send connector that can relay through exchange online protection in Office 365
#Must be run from the on prem Exchange Management Shell
#WARNING: This will use the wildcard * for sending, so please consider changing "addressSpaces" to some testing domains, so you know this works before routing everything.
#WARNING: You must remove your existing internet send connector if you wish for this to work with 100% of all email.
#Author: @michael_mardahl (github.com/mardahl)
#License: MIT - please keep author credits.
$hybridConnector = Get-SendConnector *365*
$smartHost = Resolve-DnsName $hybridConnector.AddressSpaces.Address -Type MX