Skip to content

Instantly share code, notes, and snippets.

Avatar

Bill Long bill-long

View GitHub Profile
View Set-SecureChannelFromHash.ps1
$lastByteOfHash = ((New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider).ComputeHash((New-Object -TypeName System.Text.UTF8Encoding).GetBytes($env:computername))) | Select-Object -Last 1
$site = [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite()
$domainDCsInSite = @([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().FindAllDiscoverableDomainControllers($site.Name)) | Sort-Object Name
$domainNetbiosName = (Get-ADDomain -Current LocalComputer).NetBIOSName
$myDCOffset = $lastByteOfHash % $domainDCsInSite.Count
$myDC = $domainDCsInSite[$myDCOffset]
$dcShortName = $myDC.Name.Substring(0, $myDC.Name.IndexOf("."))
$secureChannelTarget = "$domainNetbiosName\$dcShortName"
Write-Host "Setting secure channel to" $secureChannelTarget
View Check-MailEnabledPublicFoldersInChildDomains.ps1
$forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$rootDomain = $forest.RootDomain
$rootDN = $rootDomain.GetDirectoryEntry().distinguishedName
Write-Host "Root domain:" $rootDN
Set-ADServerSettings -ViewEntireForest $true
Write-Progress -Activity "Retrieving all MailPublicFolder objects"
View Test-SidTranslation.ps1
$forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$gc = $forest.FindGlobalCatalog()
$searcher = $gc.GetDirectorySearcher()
$searcher.Filter = "(&(objectClass=user)(objectSID=*))"
# Since we're not setting a page size, this will return 1000 items and then stop
$objects = $searcher.FindAll()
$sidList = @()
foreach ($o in $objects) {
$sid = New-Object System.Security.Principal.SecurityIdentifier(($o.Properties["objectSid"][0]), 0)
@bill-long
bill-long / CreateAndStartAllCountersPerfmon.ps1
Created Oct 23, 2020
Start perfmon with all counters, all instances, updating every 1 minute
View CreateAndStartAllCountersPerfmon.ps1
get-counter -ListSet * | Sort CounterSetName | % { ("\\localhost\" + $_.CounterSetName + "\*") } | Out-File .\allcounters.txt
logman create counter -n "All Counters" -cf .\allcounters.txt -rf 8:00:00 -si 00:01:00
logman start "All Counters"
View Move-ResidentPublicFolders.ps1
# Move-ResidentPublicFolders
#
# This script can be used to move all public folders from one mailbox
# to another in batches. Simply run the script, wait for the move to
# complete, then run the script again. Repeat until all folders are
# moved.
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
View CreateLotsOfPFsInMailbox.ps1
# Create-LotsOfPFs.ps1
#
# Creates 100,000 public folders
param([Parameter(Mandatory=$true)] $MailboxName)
function GetPublicFolderWithRetry($path) {
$startingCount = $Error.Count
$result = Get-PublicFolder $path -ErrorAction SilentlyContinue
if ($Error.Count -gt $startingCount) {
"Retrying..."
View CheckIfDumpsterReplicated.ps1
"\FolderA\Folder1" | % {
$folder = Get-PublicFolder $_ -Mailbox (Get-OrganizationConfig).RootPublicFolderMailbox.ToString()
$contentMailbox = $folder.ContentMailboxName
$dumpsterId = $folder.DumpsterEntryId
$dumpsterInContentMailbox = Get-PublicFolder $dumpsterId -Mailbox $contentMailbox -ErrorAction SilentlyContinue
if ($dumpsterInContentMailbox -ne $null) {
"Deletions should work."
} else {
"Deletions should not work."
}
View CheckFolderExists.ps1
function CheckFolderExists($folderToTest) {
$mbxs = Get-Mailbox -PublicFolder
Write-Output "Found $($mbxs.Count) public folder mailboxes"
$good = @()
$bad = @()
for ($i = 0; $i -lt $mbxs.Count; $i++) {
Write-Progress -Activity ($mbxs[$i].Identity) -PercentComplete ($i * 100 / $mbxs.Count)
$result = $null
$result = Get-PublicFolder $foldertoTest -Mailbox ($mbxs[$i].Identity) -ErrorAction SilentlyContinue
if ($null -ne $result) {
View Remove-SelfPermission.ps1
# Remove-SelfPermission.ps1
param($alias)
$searcher = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().FindGlobalCatalog().GetDirectorySearcher()
$searcher.Filter = "(mailnickname=$alias)"
$user = $searcher.FindOne()
if ($null -eq $user)
{
Write-Host "User not found."
View Add-SelfPermission.ps1
# Add-SelfPermission.ps1
param($alias)
$searcher = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().FindGlobalCatalog().GetDirectorySearcher()
$searcher.Filter = "(mailnickname=$alias)"
$user = $searcher.FindOne()
if ($null -eq $user)
{
Write-Host "User not found."
You can’t perform that action at this time.