Skip to content

Instantly share code, notes, and snippets.

@IMJLA
IMJLA / Copy-GroupMemberships.ps1
Last active October 26, 2017 19:08
PowerShell script to copy group memberships from a source user to a target user in Active Directory
<#
.SYNOPSIS
Copy group memberships from a source user to a target user in Active Directory
.DESCRIPTION
The target user will be added to all groups the source user is a member of.
Existing group memberships of the target user will NOT be removed.
.PARAMETER SourceUser
The source user whose memberships are to be copied
.PARAMETER TargetUser
The target user to be added to the groups
@IMJLA
IMJLA / Copy-GroupMembers.ps1
Last active January 6, 2020 03:53
PowerShell script to add all members of a source group to a target group in Active Directory
<#
.SYNOPSIS
Add all members of a source group to a target group in Active Directory.
.DESCRIPTION
Members of the source group will be added to the target group if not already members
Existing members of the target group will not be modified.
.OUTPUTS
Results are written to the console.
.EXAMPLE
.\Copy-GroupMembers.ps1
@IMJLA
IMJLA / GadgetExchange.psm1
Last active May 8, 2018 21:36
PowerShell Module to Automatically Discover and Connect to Exchange
Function ConvertTo-ExchangeRole{
<#
.SYNOPSIS
Convert the msExchCurrentServerRoles AD attribute into the Exchange Roles it represents
.DESCRIPTION
Performs a bitwise And comparison against a provided integer and the keys from a hard-coded dictionary
Dictionary based on a table from a TechNet article
https://technet.microsoft.com/en-us/library/bb123496(EXCHG.80).aspx
.PARAMETER Roles
Integer representing the Exchange roles held by the server. Matches the msExchCurrentServerRoles AD attribute.
param(
[String]$DomainDN = 'dc=ad,dc=contoso,dc=com',
[String]$LocalBackupPath = 'C:\Windows\System32\dhcp\backup',
[String]$RemoteBackupPath = '\\fileserver\share\Backups\DHCP',
[Int32]$BackupDaysToRetain = 30
)
begin{
<#
.SYNOPSIS
Backs up Cisco UCS Manager as a scheduled task
.DESCRIPTION
All available UCS Manager backup types will be taken and compressed (ZIP) then stored in the specified location
.OUTPUTS
None. Progress is displayed via Write-Host when running the script manually, but there is no output returned.
.EXAMPLE
.\Backup-CiscoUcs.ps1 -PsSessionXml 'C:\PsSessionInfo.xml' -DecryptionKey 'PlaintextPrivateKeyGoesHere' -BackupLocation 'C:\Backups'
.NOTES
function Copy-File {
param(
#Path to the source file
[Parameter(
Mandatory = $True,
Position = 0
)]
[String]$SourceFilePath,
@IMJLA
IMJLA / Read-FolderBrowserDialog.ps1
Last active January 14, 2024 05:43
A folder browser dialog with an address bar in native PowerShell
$AssemblyFullName = 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
$Assembly = [System.Reflection.Assembly]::Load($AssemblyFullName)
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.AddExtension = $false
$OpenFileDialog.CheckFileExists = $false
$OpenFileDialog.DereferenceLinks = $true
$OpenFileDialog.Filter = "Folders|`n"
$OpenFileDialog.Multiselect = $false
$OpenFileDialog.Title = "Select folder"
$OpenFileDialogType = $OpenFileDialog.GetType()
On Error Resume Next
strOldHostname = InputBox ("Enter the hostname to be removed from DNS. Just the hostname, please; not the FQDN.","Enter the host name to be removed","")
'Track when the script began
StartTime = Now
'Begin the log file
Set objShell = CreateObject("WScript.Shell")
strLocalAppDataPath = objShell.ExpandEnvironmentStrings("%LocalAppData%")
param (
# Name of the group whose members to retrieve
[string]$GroupName
)
function Search-Directory {
# Uses the .NET System.DirectoryServices Namespace to perform an LDAP search
param (
<#
.SYNOPSIS
Identify computer certificates on a Windows computer that will expire within the next 30 days.
.DESCRIPTION
Functions as a Custom EXE sensor for PRTG to monitor certificate expiration.
#>
param(
# Name of the computer to search for expiring certificates