Skip to content

Instantly share code, notes, and snippets.

@ScriptingPro
ScriptingPro / get linked attributes.ps1
Last active March 8, 2019 21:54
look in AD schema and list all linked attributes
$Schema = [DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Schema
$Schema.FindAllProperties() | ?{$_.link}
@ScriptingPro
ScriptingPro / Save-Credential.ps1
Created November 28, 2018 00:10
save powershell credential to xml
<#
powershell save credentials to xml file
export-clixml powershell credentials
powershell save credentials to disk
powershell script credential file
powershell write credential to file
#>
# this way for v4
function savecred
$thisguid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$guidobj = New-Object System.Guid
[guid]::TryParse($thisguid,[ref]$guidobj)
@ScriptingPro
ScriptingPro / AD Object Property Types and New-AD* Cmdlet Parameter Types.ps1
Created September 5, 2018 14:20
AD Object Property Types and New-AD* Cmdlet Parameter Types
# Determine which AD Group attributes are of type string
$GetGroupStringProperties = $((Get-ADGroup -Filter * -ResultSetSize 1 -Properties *).psobject.properties | ?{$_.TypeNameOfValue -eq "System.String"}).Name
# Determine which parameters are expecting strings for New-AdGroup
$NewGroupStringParameters = $((Get-Help New-ADGroup).parameters.parameter | ?{$_.type.name -eq "string"}).Name
@ScriptingPro
ScriptingPro / Net framework versions installed.ps1
Created August 14, 2018 19:35
Determine .NET versions installed powershell
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select PSChildName, Version, Release
@ScriptingPro
ScriptingPro / find_it.ps1
Last active September 18, 2020 13:01
Search your PS1 files and open in ISE
# Find PowerShell Code Snippets Function
function findit
{
param
(
[Parameter(Mandatory=$True,Position=0)][string]$SearchString,
[Parameter(Mandatory=$False)]$Path = "$env:USERPROFILE\Documents",
[Parameter(Mandatory=$False)]$Filter = "*.ps1"
)
Get-ChildItem -Path $Path -Filter $Filter -Recurse | Select-String $SearchString | select path, @{n="MatchingLines";e={"$($_.LineNumber.tostring("000")): $($_.Line -replace "^[ \t]*",'')"}} | group path | select name, @{n="Matches";e={$_.Group.MatchingLines | Out-String}} | Out-GridView -PassThru | %{psedit -filenames $_.name}
@ScriptingPro
ScriptingPro / Misc .NET Classes and Methods
Created April 5, 2018 14:12
Use Misc .NET Classes and Methods from PowerShell
[System.Net.Dns]::GetHostByName([System.Environment]::MachineName).HostName
@ScriptingPro
ScriptingPro / FQDN_HostName.ps1
Created March 29, 2018 22:06
Get FQDN DNS HostName of current Computer
[System.Net.Dns]::GetHostByName([System.Environment]::MachineName).HostName
# directoryentry (connect to specific dc:port)
$de = ([ADSI]"LDAP://$($ADDomainController.HostName):$($ADDomainController.LdapPort)")
# directorysearcher
$ds = New-Object System.DirectoryServices.DirectorySearcher($de,"(objectclass=user)")
$ds.PageSize=1000
# invoke
$ds.FindAll() | %{"do stuff with $_"}
$thisuser = $ds.FindOne()
@ScriptingPro
ScriptingPro / encoding-helpers.ps1
Created January 26, 2018 22:57 — forked from jpoehls/encoding-helpers.ps1
Convert-FileEncoding and Get-FileEncoding
<#
.SYNOPSIS
Converts files to the given encoding.
Matches the include pattern recursively under the given path.
.EXAMPLE
Convert-FileEncoding -Include *.js -Path scripts -Encoding UTF8
#>
function Convert-FileEncoding([string]$Include, [string]$Path, [string]$Encoding='UTF8') {
$count = 0