This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define your query filter | |
$LDAPfilter = "(samaccountname=*)" | |
# define the object attributes you want returned | |
$Attributes = @" | |
samaccountname | |
givenname | |
surname | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SplitHereString = @" | |
a | |
b | |
c | |
"@ -split [System.Environment]::NewLine | |
$SplitHereString.GetType() # notice it's String[] / System.Array | |
$ConstructedArray = @('a','b','c') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Net.Dns]::GetHostByName([System.Environment]::MachineName).HostName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Net.Dns]::GetHostByName([System.Environment]::MachineName).HostName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$thisguid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' | |
$guidobj = New-Object System.Guid | |
[guid]::TryParse($thisguid,[ref]$guidobj) |