Skip to content

Instantly share code, notes, and snippets.

@ScriptingPro
ScriptingPro / Array Collections.ps1
Created January 5, 2018 05:12
Playing with Collections
$SplitHereString = @"
a
b
c
"@ -split [System.Environment]::NewLine
$SplitHereString.GetType() # notice it's String[] / System.Array
$ConstructedArray = @('a','b','c')
@ScriptingPro
ScriptingPro / PowerShell LDAP.ps1
Created January 4, 2018 22:33
LDAP bind to server/port with PowerShell using DirectoryEntry Class and query with DirectorySearcher Class
# define your query filter
$LDAPfilter = "(samaccountname=*)"
# define the object attributes you want returned
$Attributes = @"
samaccountname
givenname
surname
mail
@ScriptingPro
ScriptingPro / AD Exchange Queries.ps1
Last active September 27, 2018 18:47
AD/ADSI/LDAP MSExchange related queries (without using Exchange Management Shell cmdlets)
#Get Exchange Servers
Get-ADObject -SearchBase $(Get-ADRootDSE).configurationNamingContext -Filter {objectCategory -eq "msExchExchangeServer"}
# Find well-known Exchange groups in Active Directory
Get-ADObject $(Get-ADRootDSE).configurationNamingContext -Filter {objectclass -eq "msExchConfigurationContainer"} -Properties otherwellKnownObjects | select -ExpandProperty otherwellKnownObjects | %{$_.Split(":")[-1]}
@ScriptingPro
ScriptingPro / LDAP-Request.ps1
Created November 22, 2017 18:06
LdapConnection AddRequest SendRequest
$AuthenticationType = [System.DirectoryServices.AuthenticationTypes]::Secure
$DirectoryConnection = New-Object -TypeName System.DirectoryServices.Protocols.LdapConnection -ArgumentList "ldapserver.domain.com:777,uid=newuser,ou=people,dc=company,dc=com", $password , $AuthenticationType
$DirectoryConnection.Bind()
$DirectoryRequest = New-Object -TypeName System.DirectoryServices.Protocols.AddRequest
$DirectoryRequest.DistinguishedName = "uid= xxxx, ou=user, o=company"
$DirectoryRequest.Attributes.Add((New-Object -TypeName System.DirectoryServices.Protocols.DirectoryAttribute -ArgumentList "objectclass",@("top","organizationalPerson","person","inetorgperson","inetuser","mailrecipient","pwmuser","posixAccount"))) | Out-Null
$DirectoryRequest.Attributes.Add((New-Object -TypeName System.DirectoryServices.Protocols.DirectoryAttribute -ArgumentList "cn",($FirstName+" "+$LastName))) | Out-Null
$DirectoryConnection.SendRequest($DirectoryRequest)
@ScriptingPro
ScriptingPro / README-Template.md
Created October 26, 2017 00:35 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@ScriptingPro
ScriptingPro / powershell get configurationNamingContext.ps1
Last active February 5, 2019 19:35
different ways to get configurationNamingContext
[ADSI]"LDAP://RootDSE" | fl *
([ADSI]"LDAP://RootDSE").configurationNamingContext
([ADSI]"LDAP://RootDSE").get("configurationNamingContext")
# Domain Distinguished Name
([ADSI]"LDAP://RootDSE").defaultNamingContext
@ScriptingPro
ScriptingPro / find dupe files by hash.ps1
Created October 25, 2017 23:57
powershell find duplicate files
# powershell find duplicate files md5
# powershell get childitem filter duplicates
# script to find duplicate files windows
# powershell duplicate files md5
gci * -Recurse | get-filehash -Algorithm MD5 | Group-Object hash | ?{$_.count -gt 1} | select @{n='DupeCount';e={$_.Count}}, @{n='DupeFiles';e={$_.Group.Path -join [System.Environment]::NewLine}} | Out-GridView
@ScriptingPro
ScriptingPro / System.DirectoryServices.ActiveDirectory.ps1
Last active February 16, 2024 00:42
Query Active Directory without ActiveDirectory Module
#get dnsroot
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name
#get domain distinguishedname
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry().Properties["distinguishedName"]
#list domain controllers
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().FindAllDomainControllers().Name
#get PDC
@ScriptingPro
ScriptingPro / Determine .NET Framework Versions Installed.ps1
Last active June 19, 2018 23:33
Determine .NET Framework Versions Installed
# check dot net version
gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | gp -name Version,Release -EA 0 | ?{ $_.PSChildName -match '^(?!S)\p{L}'} | select PSChildName, Version, Release
# how to check net framework version installed
# where can i find net framework on my computer
# verify net framework version installed
# determine .net framework versions
# where to find net framework on computer
@ScriptingPro
ScriptingPro / powershell-set-terminal-services-profile-path.ps1
Last active September 27, 2021 12:33
PowerShell Set Terminal Services Profile Path
<#
Set Active Directory Users Terminal Services Profile Path Using PowerShell
There is no remote desktop services profile path attribute, because TerminalServicesProfilePath is saved in the Active Directory user object's UserParameters attribute as a binary blob
This snippet will find ADUsers that match $TSProfilePath_OLD and set their remote desktop services profile path to $TSProfilePath_NEW
#>
# Need Active Directory Cmdlets
Import-Module ActiveDirectory
# Change TerminalServicesProfilePath only on users that are currently pointing to: