Instantly share code, notes, and snippets.

View module_update_check
Get-InstalledModule | Select-Object Name, @{n='Installed';e={$_.Version}}, @{n='Available';e={(Find-Module -Name $_.Name).Version}} | Where-Object {$_.Available -gt $_.Installed}
View reset-lcm
################################################################################
Param(
[string[]]$Computername = "localhost"
)
[DscLocalConfigurationManager()]
Configuration ResetLCM {
Param([string[]]$Computername)
View schedule_cron
cron(Minutes | Hours | Day-of-month | Month | Day-of-week | Year)
cron(0 0/4 * * ? *) Every 4 hours
cron(0 10 * * ? *) 10:00AM UTC everyday
cron(15 12 * * ? *) 12:15PM UTC everyday
cron(0 18 ? * MON-FRI *) 6:00PM UTC every Mon-Fri
cron(0 8 1 * ? *) 8:00AM UTC every first day of the month
cron(0/10 * ? * MON-FRI *) Every 10 min Mon-Fri
cron(0/5 8-17 ? * MON-FRI *)Every 5 minutes Mon-Fri between 8:00AM - 5:55PM UTC
cron(0 9 ? * 2#1 *) 9:00AM UTC first Monday of each month
View ps_lambda
#Download the .NET Core 2.1 SDK from https://www.microsoft.com/net/download
Install-Module AWSPowerShell.NetCore
Install-Module AWSLambdaPSCore
Import-Module AWSPowerShell.NetCore
Import-Module AWSLambdaPSCore
Get-Command -Module AWSLambdaPSCore
New-Item PSLambda -ItemType Directory
View winrm
#------------------------------------------------------
#ENABLE WINRM
#https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/enable-psremoting?view=powershell-6
#according to documentation this runs Set-WSManQuickConfig which basically does all the same stuff as the quickconfig
Enable-PSRemoting
#alternatively use this - but documentation indicates it's not as thorough
winrm quickconfig
#to turn back off:
Disable-PSRemoting
#------------------------------------------------------
View quickJSON
#install-module ClipboardText
#super fast PS way to create quick JSON
ConvertTo-Json -Compress -InputObject @{
JsonItem1 = "I Am Item1 content"
JsonItem2 = "I Am Item2 content"
JsonItem3 = "I Am Item3 content"
} | Set-ClipboardText
View Get-ServerLogs
<#
.SYNOPSIS
Retrieves specified logs from remote host for time period specified
.DESCRIPTION
Establishes a remote connection to specified device and queries server logs based on user specified criteria. (Log name, Log Level, Start and End times). If user does not provide log search criteria, a set of defaults are set: [System, Application with Critical, Errors, and Warnings for the last 24 hours]. If no logs are found that match the criteria a result is returned to the user to easily place in a ticket or other correspondence.
.EXAMPLE
$creds = Get-Credential;Get-ServerLogs -HostName Server01 -Credential $creds
Retrieves server logs with all defaults: System & Application will be queried for Warning, Error, Critical, for the last 24 hours. User will be prompted to supply creds.
.EXAMPLE
View pscore_winModules
<#
Most of the modules that ship as part of Windows (for example, DnsClient, Hyper-V, NetTCPIP, Storage, etc.) and other Microsoft products including Azure and Office have not been explicitly ported to .NET Core yet.
By installing the WindowsPSModulePath module, you can use Windows PowerShell modules by appending the Windows PowerShell PSModulePath to your PowerShell Core PSModulePath.
#>
# Add `-Scope CurrentUser` if you're installing as non-admin
Install-Module WindowsPSModulePath -Force
# Add this line to your profile if you always want Windows PowerShell PSModulePath
Add-WindowsPSModulePath
View module_info
#C:\Program Files\PowerShell\Modules
#C:\Program Files\WindowsPowerShell\Modules
$a = Get-Module powershellget -ListAvailable
$a.Path
Get-Module -ListAvailable $module | Remove-Module -Force;Install-Module $module -Repository PSGallery -Force -AllowClobber
View vscode_ps_snippets
"Help": {
"prefix": "help",
"body": [
"<#",
".SYNOPSIS",
"\tShort description",
".DESCRIPTION",
"\tLong description",
".EXAMPLE",
"\tC:\\PS>",