View SetDNS
$dns1 = "192.168.1.4"
$dns2 = "192.168.1.5"
#-----------------------------------------------------------
#i want to set the DNS for all adapters
try{
$adapters = Get-NetAdapter -ErrorAction Stop
foreach($adapter in $adapters){
Set-DnsClientServerAddress -InterfaceAlias $adapter.InterfaceAlias -ServerAddresses $dns1, $dns2 | Out-Null
}
}
View Test-RunningAsAdmin
<#
.Synopsis
Tests if PowerShell Session is running as Admin
.DESCRIPTION
Evaluates if current PowerShell session is running under the context of an Administrator
.EXAMPLE
Test-RunningAsAdmin
This will verify if the current PowerShell session is running under the context of an Administrator
.OUTPUTS
View profile_edit
notepad $profile.CurrentUserAllHosts
View ps_classes
class HelperStuff
{
# get first character of string and throw exception
# when string is empty or multi-line
static [char] GetFirstCharacter([string]$Text)
{
if ($Text.Length -eq 0) { throw 'String is empty' }
if ($Text.Contains("`n")) { throw 'String contains multiple lines' }
return $Text[0]
}
View encode_powershell
[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes('Import-PfxCertificate -FilePath C:\tmp\BrowserCertificate.p12 -Password (Get-Content -Path C:\tmp\pass.txt | ConvertTo-SecureString -Key (Get-Content -Path C:\tmp\registry-backup070517.key)) -CertStoreLocation Cert:\CurrentUser\My -Exportable'))
powershell.exe -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -EncodedCommand SQBtAHAAbwByAHQALQBQAGYAeABDAGUAcgB0AGkAZgBpAGMAYQB0AGUAIAAtAEYAaQBsAGUAUABhAHQAaAAgAEMAOgBcAHQAbQBwAFwAQgByAG8AdwBzAGUAcgBDAGUAcgB0AGkAZ
gBpAGMAYQB0AGUALgBwADEAMgAgAC0AUABhAHMAcwB3AG8AcgBkACAAKABHAGUAdAAtAEMAbwBuAHQAZQBuAHQAIAAtAFAAYQB0AGgAIABDADoAXAB0AG0AcABcAHAAYQBzAHMALg
B0AHgAdAAgAHwAIABDAG8AbgB2AGUAcgB0AFQAbwAtAFMAZQBjAHUAcgBlAFMAdAByAGkAbgBnACAALQBLAGUAeQAgACgARwBlAHQALQBDAG8AbgB0AGUAbgB0ACAALQBQAGEAdAB
oACAAQwA6AFwAdABtAHAAXAByAGUAZwBpAHMAdAByAHkALQBiAGEAYwBrAHUAcAAwADcAMAA1ADEANwAuAGsAZQB5ACkAKQAgAC0AQwBlAHIAdABTAHQAbwByAGUATABvAGMAYQB0
AGkAbwBuACAAQwBlAHIAdAA6AFwAQwB1AHIAcgBlAG4AdABVAHMAZQB
View ldap
#it is possible to query ad without ad cmdlets or rsat on device using ldap
$filter = '(&(objectCategory=computer))'
$searcher = [ADSISearcher]$filter
# search results only
$searcher.FindAll()
# access to directory entry objects with more details
$searcher.FindAll().GetDirectoryEntry() | Select-Object -Property *
View certs
#requires -Version 5
# this is where the cert file will be saved
$Path = "$env:temp\codeSignCert.pfx"
# you'll need this password to load the PFX file later
$Password = Read-Host -Prompt 'Enter new password to protect certificate' -AsSecureString
# create cert, export to file, then delete again
$cert = New-SelfSignedCertificate -KeyUsage DigitalSignature -KeySpec Signature -FriendlyName 'IT Sec Department' -Subject CN=SecurityDepartment -KeyExportPolicy ExportableEncrypted -CertStoreLocation Cert:\CurrentUser\My -NotAfter (Get-Date).AddYears(5) -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.3')
View Secure-Creds
#note: this only works when running from the machine the creds were created on, by the user who created them
#create a file to store encypted credentials
$Path = "$home\Desktop\sec_local.xml"
#now enter your user creds
[PSCustomObject]@{
User1 = Get-Credential -Message User1
User2 = Get-Credential -Message User2
} | Export-Clixml -Path $Path
View Set-RegistryKey
<#
.Synopsis
Will create a string value in registry key specified
.DESCRIPTION
Evaluates provided registry path and determines if key is present. Key will be created if not found. Once verified the string value specified will be created in the registry location.
.PARAMETER RegKeyPath
Registry key path - must be in PS shorthand. Ex: HKLM:\SECURITY
.PARAMETER Name
The value name to be created. Equivalent to REG_SZ
.PARAMETER Value
View Get-RegistryValue
<#
.Synopsis
Retrieves the data value of a specified registry value name
.DESCRIPTION
Returns the data contents of a registry keys value name specified by the user
.PARAMETER RegKeyPath
Registry key path - must be in PS shorthand. Ex: HKLM:\SECURITY
.PARAMETER Name
The value name to be checked.
.EXAMPLE