Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
mattmcnabb / Set-MsolUserLicense.ps1
Created January 15, 2015 01:33
Add -Whatif to MSOnline Cmdlets
Function Set-MsolUserLicense
{
[CmdletBinding(DefaultParameterSetName='SetUserLicenses__0', SupportsShouldProcess=$true)]
param
(
[Parameter(ParameterSetName='SetUserLicenses__0', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[guid]
$ObjectId,
[Parameter(ParameterSetName='SetUserLicensesByUpn__0', ValueFromPipelineByPropertyName=$true)]
[Parameter(ParameterSetName='SetUserLicenses__0', ValueFromPipelineByPropertyName=$true)]
@mattmcnabb
mattmcnabb / Set-GpoStatus.ps1
Last active January 5, 2024 01:04
Set the status of a Group Policy Object with Powershell
Function Set-GPOStatus
{
<#
.Synopsis
Set the status of a Group Policy Object
.Description
Sets the status of one or more Group Policy objects.
.Example
PS C:\> Get-Gpo MyGPO | Set-GPOStatus -Status AllSettingsEnabled
.Example
@mattmcnabb
mattmcnabb / Test-ConditionalParameter.ps1
Last active August 29, 2015 14:19
Powershell Conditional Dynamic Parameters
function Test-ConditionalParameter
{
param
(
[validateset('Value1','Value2')]
[parameter()]
$Parameter1
)
dynamicparam
@mattmcnabb
mattmcnabb / RejoinRemix.ps1
Last active February 18, 2018 23:11
Rejoin a Computer to a Domain - Dance Remix
<#
.SYNOPSIS
This script disjoins a computer from an Active Directory domain, performs a reboot and upon coming back up
joins it to the domain again and performs another reboot.
.NOTES
Requirements: You must have local admin rights on the remote computer to connect to the remote computer
.PARAMETER Computername
The name of the computer to rejoin to a domain
.PARAMETER DomainName
The NetBIOS or FQDN of the domain to rejoin the computer to
@mattmcnabb
mattmcnabb / Test-BeginBlock
Created May 1, 2015 22:48
Begin Block Variable
function Test-BeginBlock
{
[CmdletBinding()]
param
(
[parameter(ValueFromPipeline)]
$Parameter1
)
begin { $Variable1 = 'whatev' }
@mattmcnabb
mattmcnabb / Set-WorkingDirectory.ps1
Last active August 29, 2015 14:20
Powershell ISE: Automatically change working directory
$null = Register-ObjectEvent -InputObject $psISE.PowerShellTabs.SelectedPowerShellTab -EventName 'PropertyChanged' -Action {
if($args[1].PropertyName -eq 'LastEditorWithFocus' -and $env:AutoChangeLocation -eq $true)
{
$Location = Get-Location
$NewLocation = split-path $psISE.PowerShellTabs.SelectedPowerShellTab.Files.SelectedFile.FullPath
if ($Location.path -ne $NewLocation)
{
Set-Location $NewLocation
Out-Host -InputObject ' '
prompt
@mattmcnabb
mattmcnabb / IndentStyle.ps1
Last active August 29, 2015 14:21
IndentStyle
# Indent style for multiline hashtables
# I tend to think of the assignment and opening '@{' as
# one token.
$Capabilities = @{
MilitaryService = $false
DrinkAlcohol = $false
Vote = $false
}
# This usage works nearly everywhere for me
@mattmcnabb
mattmcnabb / ConnectExchange.ps1
Last active August 29, 2015 14:21
Use Powershell to Manage Office 365
$Credential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $Credential -Authentication Basic -AllowRedirection
Import-PSSession $Session
@mattmcnabb
mattmcnabb / ConnectO365Other.ps1
Created May 18, 2015 00:40
Connect to Sharepoint, Lync, and Azure Active Directory
# Connect to Azure Active Directory to manage users, groups and licensing
Connect-MsolService -Credential $Credential
# Connect to Sharepoint Online for domain psescape.onmicrosoft.com
Connect-SpoService -Credential $Credential -Url https://psescape-admin.sharepoint.com
# Connect to Lync Online
$Session = New-CsOnlineSession -Credential $Credential
Import-PSSession $Session
@mattmcnabb
mattmcnabb / Connect-O365.ps1
Created May 18, 2015 00:51
Connect to Office 365 Services Using the O365 Admin Module
Connect-O365 -Services AzureActiveDirectory, Exchange, Sharepoint, Skype -Credential $Credential