Skip to content

Instantly share code, notes, and snippets.

@adamalbers
adamalbers / Get FQDN.ps1
Created June 14, 2022 03:03
For some reason there isn't an $Env: variable for the FQDN so this is the easiest way I've found to get it.
$fqdn = ([System.Net.Dns]::GetHostByName($env:computerName)).HostName
Install-Module ExchangeOnlineManagement
Install-Module AIPService
Connect-ExchangeOnline
Connect-AIPService
Enable-AIPService
$licenseURL = (Get-AipServiceConfiguration).LicensingIntranetDistributionPointUrl
$irmConfig = Get-IRMConfiguration
$list = $irmConfig.LicensingLocation
<#
.NET Framework version | Minimum value
.NET Framework 4.5 | 378389
.NET Framework 4.5.1 | 378675
.NET Framework 4.5.2 | 379893
.NET Framework 4.6 | 393295
.NET Framework 4.6.1 | 394254
.NET Framework 4.6.2 | 394802
.NET Framework 4.7 | 460798
.NET Framework 4.7.1 | 461308
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
<#
This script fixes the file permissions so that members of $adminGroup can access the redirected
folders of users. It also ensures that the users remain the owners of their own folders so that
folder redirection does not break.
PRO TIP: Make an explicit group to access the folders. DO NOT use a built-in group like Domain Admins or Administrators.
Taken from jonahzona on Spiceworks forum. All I did was clean up the formatting and change the variable names.
https://community.spiceworks.com/topic/1948116-domain-admins-can-not-access-folders-used-for-folder-redirection
#>
# Where to output the Html and Xml reports
$reportDirectory = 'C:\path\to\GPO\Reports'
# Create $reportDirectory if it does not exist
if (-not $(Test-Path $reportDirectory)) {
New-Item -Path "$reportDirectory" -ItemType Directory -Force
}
# Create one report that contains all GPOs in it
Get-GPOReport -All -ReportType Html -Path "$($reportDirectory)\_All-GPOs.html"
$domainRoles= Get-ADDomain | Select-Object InfrastructureMaster, RIDMaster, PDCEmulator
$forestRoles = Get-ADForest | Select-Object DomainNamingMaster, SchemaMaster
$fsmoRoles = New-Object -TypeName psobject
$fsmoRoles | Add-Member -NotePropertyName 'InfrastructureMaster' -NotePropertyValue $($domainRoles.InfrastructureMaster)
$fsmoRoles | Add-Member -NotePropertyName 'RIDMaster' -NotePropertyValue $($domainRoles.RIDMaster)
$fsmoRoles | Add-Member -NotePropertyName 'PDCEmulator' -NotePropertyValue $($domainRoles.PDCEmulator)
$fsmoRoles | Add-Member -NotePropertyName 'DomainNamingMaster' -NotePropertyValue $($forestRoles.DomainNamingMaster)
$fsmoRoles | Add-Member -NotePropertyName 'SchemaMaster' -NotePropertyValue $($forestRoles.SchemaMaster)
# The #!ps is for pasting into Connectwise Control. You don't need it otherwise.
#!ps
function killProcess {
param (
[Parameter(Mandatory = $true)]
$thisProcess
)
try {
Stop-Process -Name $thisProcess -Force -Confirm:$false
# Quarantines any emails using $blockedCharsets
# Supported charsets: https://docs.microsoft.com/en-us/exchange/mail-flow-best-practices/remote-domains/supported-character-sets
$allowedCharsets = @('UTF-8','US-ASCII','ISO-8859-1','WINDOWS-1252')
$blockedCharsetWords = @('big5','euc','gb','iso','koi','ks','ns','sen','shift','windows')
New-TransportRule -Name "Block Abnormal Charsets" -ContentCharacterSetContainsWords $blockedCharsetWords -ExceptIfContentCharacterSetContainsWords $allowedCharsets -Quarantine $true -Priority 0
#!ps
# The #!ps is for pasting into Connectwise Control. You don't need it otherwise.
function killProcess {
param (
[Parameter(Mandatory = $true)]
$thisProcess
)
try {
Stop-Process -Name $thisProcess -Force -Confirm:$false