Skip to content

Instantly share code, notes, and snippets.

@evetsleep
evetsleep / Export-ServerCertificate.psm1
Created February 3, 2022 21:05
Export server certificates to variables and PEM formats
function Export-ServerCertificate {
[CmdletBinding()]Param(
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('HostName')]
[String]
$ComputerName,
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('TCPPort')]
[ValidateRange(1,65000)]
@evetsleep
evetsleep / Send-Mail.ps1
Created March 25, 2020 17:00
Send mail using .NET
function Send-Mail {
[CmdletBinding()]Param(
[Parameter(Mandatory)]
[String]
$From,
[Parameter(Mandatory)]
[String[]]
$To,
function Reset-ADPassword {
[CmdletBinding(SupportsShouldProcess)]Param(
[Parameter(Position=0,Mandatory)]
[String]
$UserName,
[Parameter(Position=1)]
[String]
$Domain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name,
@evetsleep
evetsleep / Set-OtherMails.ps1
Created October 4, 2019 12:45
Set OtherMails via Graph
[CmdletBinding()]Param(
[Parameter(Mandatory)]
[String]
$UserPrincipalName,
[Parameter(Mandatory)]
[AllowEmptyString()]
[String]
$NewValue,
function PageMembers {
[CmdletBinding()]Param(
[Parameter(ValueFromPipeline)]
[System.DirectoryServices.SearchResult]$SearchResult
)
process {
<#
When getting a search result back for a group object you will likely get
either a member property OR a member;range=0-1499. If you get the later
$arrayList = New-Object -TypeName System.Collections.Generic.List[int]
0..9999 | ForEach-Object { $arrayList.Add($PSItem) }
$iterations = 1000
$results = New-Object -TypeName System.Collections.Generic.List[PSCustomObject]
1..$iterations | ForEach-Object {
$number = Get-Random -Maximum 9999
$resultObject = [PSCustomObject]@{
whereMethod = (Measure-Command -Expression { $arrayList.where{$PSItem -eq $number} }).Milliseconds
$testTitle = 'stuff'
$results = New-Object System.Collections.Generic.List[PSCUstomObject]
0..99 | ForEach-Object {
# Used to store the timing of the query and the update times.
$testResults = [PSCustomObject]@{
Test1Query = $Null
Test1UpdateAvgMS = $Null
Test2Query = $Null
Test2UpdateAvgMS = $Null
}
[CmdletBinding(SupportsShouldProcess)]Param()
#region Collect user and group information
<#
Use a custom object to store what the group membership SHOULD look like.
We'll use this later to do a comparison with the current group members
to see who we need to add\remove.
#>
$correctGroupState = [PSCustomObject]@{
Administrative = New-Object -TypeName System.Collections.Generic.List[String]
[CmdletBinding(SupportsShouldProcess)]Param()
$date = get-date
$date = $date.ToString("yyyyMMdd")
#set log file path
$logFile = "c:\temp\" + $date + "_remove_disabled_users_rights.csv"
try {
$disabledUsers = Get-ADUser -Filter "enabled -eq '$false' -and name -ne 'guest' -and name -ne 'krbtgt'" -Properties memberOf -ErrorAction STOP
#requires -Module ActiveDirectory
[CmdletBinding(SupportsShouldProcess)]Param()
$PSDefaultParameterValues = @{'*:ErrorAction'='STOP'}
$dcHash = @{}
try {
Get-ADForest | Select-Object -ExpandProperty Domains | ForEach-Object {
$domain = $psitem
$dc = Get-ADDomainController -Discover -DomainName $domain | Select-Object -ExpandProperty hostname