Skip to content

Instantly share code, notes, and snippets.

View h3nryza's full-sized avatar

H3nryza h3nryza

View GitHub Profile
@h3nryza
h3nryza / powerShellDates.ps1
Created July 17, 2018 17:42
Powershell the date thing
Get-Date
(Get-Date).AddDays(1)
(Get-Date).AddDays(1)
(Get-Date).AddHours(1)
(Get-Date).AddMilliseconds(1)
(Get-Date).AddMinutes(1)
(Get-Date).AddMonths(1)
(Get-Date).AddSeconds(1)
(Get-Date).AddTicks(1)
(Get-Date).AddYears(1)
@h3nryza
h3nryza / powerShellSecretPassword.ps1
Created July 17, 2018 17:42
Powershell "secret" password convertion - Unsafe
(Get-Credential).Password |ConvertFrom-SecureString | out-file "C:\Automation\secret.txt"
$pwd = Get-Content "C:\Automation\secret.txt" | ConvertTo-SecureString
$mycreds = New-Object System.Management.Automation.PSCredential (“username”, $pwd)
@h3nryza
h3nryza / powerShellRegex.ps1
Created July 17, 2018 17:41
Regex with Powershell
$a="a,b,c,d,e,f,g"
([regex]::Matches($a, "<=,/" )).count
@h3nryza
h3nryza / powerShellVersion.ps1
Created July 17, 2018 17:40
Powershell version
PSVersionTable.PSVersion
@h3nryza
h3nryza / powerShellModulePaths.ps1
Created July 17, 2018 17:40
Powershell List all modules including paths
(Get-Module -ListAvailable *).path
@h3nryza
h3nryza / powerShellDebugPrefs.ps1
Created July 17, 2018 17:38
Powershell Debug prefs
$VerbosePreference =
<#
Continue - Show the message on the console
SilentlyContinue - do not show the message. [this is the Default action]
Stop - show the message and then halt
Inquire - prompt the user
<#
@h3nryza
h3nryza / powerShellAuditLogs.ps1
Created July 17, 2018 17:37
Powershell quick last 2 days auditlogs
Get-EventLog -LogName Application -After (Get-Date).AddDays(-2) -EntryType "Error" | export-csv .\ApplicationLog-Errors.csv
Get-EventLog -LogName Application -After (Get-Date).AddDays(-2) -EntryType "Warning" | export-csv .\ApplicationLog-Warnings.csv
Get-EventLog -LogName System -After (Get-Date).AddDays(-2) -EntryType "Error" | export-csv .\SystemLog-Errors.csv
Get-EventLog -LogName System -After (Get-Date).AddDays(-2) -EntryType "Warning" | export-csv .\SystemLog-Warnings.csv
@h3nryza
h3nryza / powerShellBase64.ps1
Created July 17, 2018 17:37
Powershell Base64
$test = -join ((65..122) | Get-Random -Count 10000 | % {[char]$_})
[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("$test"))
@h3nryza
h3nryza / powerShellADComputersLastR.ps1
Created July 17, 2018 17:36
Powershell AD users and computer last reset in the x days
Import-Module *Active*
#Windows 7, Enabled, Last 35Days
get-adcomputer -filter * -properties * | select DNSHostName,OperatingSystem,Enabled,@{N='pwdLastSet'; E={[DateTime]::FromFileTime($_.pwdLastSet)}}| where{$_.pwdLastSet -ge (get-date).adddays(-60) -and $_.OperatingSystem -like "*7*" -and $_.enabled -like "*True*"} | export-csv ADComputers.csv
#Servers, Enabled, Last 35Days
get-adcomputer -filter * -properties * | select DNSHostName,OperatingSystem,Enabled,@{N='pwdLastSet'; E={[DateTime]::FromFileTime($_.pwdLastSet)}}| where{$_.pwdLastSet -ge (get-date).adddays(-60) -and $_.OperatingSystem -like "*Server*" -and $_.enabled -like "*True*"} | export-csv ADServers.csv
@h3nryza
h3nryza / powerShellScriptExecutionDir.ps1
Created July 17, 2018 17:34
Powershell script execution directory
#Get Script Execution Directory
[System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
#OR
$PSScriptRoot
#OR
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition