Skip to content

Instantly share code, notes, and snippets.

View PshMike's full-sized avatar

PshMike PshMike

View GitHub Profile
@PshMike
PshMike / Set-ADGroupACL.ps1
Last active October 4, 2021 18:24
Set AD Group ACL
$GroupObject = Get-ADGroup 'MyGroupName'
$NTPrincipal = Get-ADUser 'myUserName'
if ($GroupObject -and $NTPrincipal) {
$acl = Get-Acl "AD:$($GroupObject.distinguishedName)"
$identity = [System.Security.Principal.IdentityReference] $NTPrincipal.SID
$adRights = [System.DirectoryServices.ActiveDirectoryRights]::WriteProperty -bor [System.DirectoryServices.ActiveDirectoryRights]::WriteDacl
Function Get-DeepADMembership
{
[cmdletbinding()]
param (
[Parameter(Mandatory,
ParameterSetName = 'ByDN')]
[string[]]$DN,
@PshMike
PshMike / try-catch.ps1
Last active March 25, 2020 06:44
try/catch/finally example
$Computer_List = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
foreach ($computer in $Computer_List)
{
$obj = [pscustomobject][ordered] @{
ComputerName = $computer
IPAddress = ''
PingTest = $false
PSRemotingEnabled = $false
}
@PshMike
PshMike / cap.ps1
Created March 22, 2020 10:27
Packet Capture using PowerShell
$cs = New-CimSession -ComputerName SERVER001
New-NetEventSession -CimSession $cs -Name mycap -LocalFilePath c:\temp\netcapture.etl
Add-NetEventPacketCaptureProvider -CimSession $cs -SessionName mycap
Start-NetEventSession -CimSession $cs -Name mycap
break
# run these next two lines to stop the capture
Stop-NetEventSession -CimSession $cs -Name mycap
Remove-NetEventSession -CimSession $cs -Name mycap
@PshMike
PshMike / buildpath.ps1
Created March 22, 2020 07:45
BuildPath
Function BuildPath
{
param(
[system.collections.arraylist]$PathElements
)
do
{
$PathElements[1] = join-path $PathElements[0] $PathElements[1]
$PathElements.RemoveRange(0,1)
@PshMike
PshMike / mapuser.ps1
Created March 22, 2020 07:28
UserMapping
<#
.SYNOPSIS
Converts Identity object schemas
.DESCRIPTION
This function will take an array of identity objects from HRS format and
convert into objects using a nested object schema with attributes specified
in an attribute mapping hashtable parameter
.EXAMPLE
$orgAttrIdMap = @{
@PshMike
PshMike / get-myADUserInfo.ps1
Last active March 18, 2020 06:05
Get Active Directory user info using ADSI with no dependency on native AD Cmdlets
Function Get-myADUserInfo
{
[CmdletBinding()]
param
(
[string[]]$Username
)
Begin