This file contains hidden or 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-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) |
This file contains hidden or 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-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) |
This file contains hidden or 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
| $a="a,b,c,d,e,f,g" | |
| ([regex]::Matches($a, "<=,/" )).count |
This file contains hidden or 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
| PSVersionTable.PSVersion |
This file contains hidden or 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-Module -ListAvailable *).path |
This file contains hidden or 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
| $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 | |
| <# |
This file contains hidden or 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-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 |
This file contains hidden or 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
| $test = -join ((65..122) | Get-Random -Count 10000 | % {[char]$_}) | |
| [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("$test")) |
This file contains hidden or 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
| 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 | |
This file contains hidden or 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 Script Execution Directory | |
| [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) | |
| #OR | |
| $PSScriptRoot | |
| #OR | |
| $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition |