Skip to content

Instantly share code, notes, and snippets.

View iyre's full-sized avatar

Miles Miller iyre

View GitHub Profile
@iyre
iyre / Set-NewUpn.ps1
Created February 20, 2020 15:20
Batch replace domain name portion of UPN in active directory
# batch replace domain name portion of UPN in active directory
$SearchBase = "OU=Domain Users, DC=contoso, DC=com"
$OldDN = "contoso.com.local"
$NewDN = "contoso.com"
Import-Module ActiveDirectory
Get-ADUser -Filter { UserPrincipalName -like "*$OldDN" } -SearchBase $SearchBase |
ForEach-Object {
Write-Host $_.Name
$Upn = $_.UserPrincipalName.Replace( $OldDN, $NewDN )
@iyre
iyre / CleanupSharedPrinters.ps1
Last active February 20, 2020 22:25
Consolidate shared printers from various servers
$NewPrintServer = 'PRINT'
$ComObject = New-Object -ComObject WScript.Network
$Map = @{
"4071" = "4071"
"4111" = "4111N"
"5001" = "4111N"
"2640" = "2640N"
}
@iyre
iyre / cisco-ap-config.py
Created February 25, 2020 02:23
python telnetlib to configure cisco ios
import getpass
import sys
import telnetlib
import os
# Variables
tacacs = '.tacacslogin'
commandsfile = 'commands.txt'
hostsfile = 'hosts.txt'
verbose = "yes"
$target = read-host "Target"
$group = read-host "Group"
$user = read-host "User"
Invoke-Command -ComputerName $target -ScriptBlock {
net localgroup $(args[0]) $(args[1]) /add
#With PS5
#Add-LocalGroupMember -Group $(args[0]) -Member $(args[1])
} -ArgumentList $group,$user
@iyre
iyre / bulk_rename.ps1
Last active June 2, 2020 01:13
powershell bulk rename
Get-ChildItem | Where-Object {$_.Name -like "* - *.wav"} | foreach {
Rename-Item $_ -NewName $_.Name.Substring(5) -whatif
}
$target = read-host -p "Target"
$key = read-host -p "Key"
slmgr $target -ipk $key
@iyre
iyre / Set-DHCPv4SubnetMask.ps1
Created March 25, 2021 15:36
Update the subnet mask for an existing DHCP scope
$ServerName = "CORP-DHCP01"
$ScopeId = "10.10.10.0"
$SubnetMask = "255.255.255.0" #This is the NEW mask that will be applied
$ServerFile = "c:\temp\dhcp_backup.xml"
$ServerFileBackup = "c:\temp\dhcp_backup2.xml"
$ScopeFile = "c:\temp\scope_$ScopeId.xml"
#backup entire server, just in case
Export-DhcpServer -ComputerName $ServerName -Leases -File $ServerFile
@iyre
iyre / Test-UserCredential.ps1
Created October 21, 2021 22:08
Test a domain user's credential, perhaps when validating a temporary password.
function Test-UserCredential {
[CmdletBinding()]
[OutputType([bool])]
param (
[pscredential]$Credential
)
begin {
if ($null -eq $Credential) { $Credential = Get-Credential }
$Domain = $Env:USERDOMAIN
@iyre
iyre / Set-ADOrgInfo.ps1
Last active November 11, 2021 23:17
update common organizational attributes in active directory using this powershell script
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][ValidateSet('Title', 'Department', 'Company')]
[string]$AttributeName = (Read-host -Prompt "Which attribute? [Title, Department, Company]"),
[Parameter(Mandatory = $true)][string]$AttributeValueOld = (Read-Host -Prompt "Old value"),
[Parameter(Mandatory = $true)][string]$AttributeValueNew = (Read-Host -Prompt "New value"),
[switch]$NoConfirm
)
begin {}
@iyre
iyre / ip_math.ps1
Created January 28, 2023 04:01
powershell ip math
function IpToInt ([ipaddress]$IPAddress) {
$IpBytes = $IPAddress.GetAddressBytes()
if ([BitConverter]::IsLittleEndian) {
[Array]::Reverse($IpBytes)
}
return [BitConverter]::ToUInt32($IpBytes, 0)
}