Skip to content

Instantly share code, notes, and snippets.

View jkavanagh58's full-sized avatar

John J Kavanagh jkavanagh58

View GitHub Profile
# Qualified Function for unlocking an AD account
function unlock-anaccount {
<#
.SYNOPSIS
Used to unlock an AD account
.DESCRIPTION
Using the provided logon name this function will attempt to unlock the AD account.
.PARAMETER logonName
This value should match the User Account samAccountName aka User Logon Name from AD Users and Computers.
.EXAMPLE
"PS Custom Object": {
"prefix": "pscustom",
"body": [
"$$obj = [pscustomobject]@{",
"\tFieldName = FieldValue;",
"}"
],
"description": "Skeleton for adding a PowerShell Custom Object"
},
# Example of an inline filter and then a calculated expression
get-adcomputer -Filter {OperatingSystem -like "*Server*" -AND Name -like "PIT*"} |
Select-Object Name,@{n="online";e={test-connection -Computer $_.Name -Count 1 -Quiet}}
$file = 'C:\etc\srv03sb.csv'
$computers = Import-Csv -Path $file -Header ComputerName, IPAdress, DNSServer1, DNSServer2, DNSServer3
foreach ($computer in $computers) {
if(Test-Connection -ComputerName $computer.ComputerName -Count 1 -ea 0) {
try {
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $computer.ComputerName -EA Stop | ? {$_.IPEnabled}
}
catch {
Write-Warning "Error occurred while querying $computer."
Function Publish-admcred {
Begin{
$path = "$home\Desktop\mycred.json"
# Remove existing cred file if exists
if (test-path $path){Remove-Item $path -force}
}
Process{
$cred = Get-Credential
$cred |
Select Username,@{n="Password"; e={$_.password | ConvertFrom-SecureString}} |
{
"Condition statement": {
"prefix": "cond",
"body": [
"${_} { ${0}; break }"
],
"description": "Switch condition statement"
},
"Credential Parameter": {
"prefix": "credparam",
Function show-installedmodules {
<#
.SYNOPSIS
Lists Installed Modules and compares installed versions compared to online version
.DESCRIPTION
Uses list of installed modules via Get-InstalledModule, and compares them to current online version using
the Find-Module returned Version. Place in profile to ensure it is loaded in all PowerShell sessions is
recommended.
.EXAMPLE
I ♥ PS > show-installedmodules
Function show-installedmodules {
<#
.SYNOPSIS
Lists Installed Modules and compares installed versions compared to online version
.DESCRIPTION
Uses list of installed modules via Get-InstalledModule, and compares them to current online version using
the Find-Module returned Version
.EXAMPLE
I ♥ PS > show-installedmodules
Example of how to use this Function
Function show-installedmodules {
#Requires -Version 5
[CmdletBinding()]
Param(
$varModules = (get-installedmodule)
)
Begin {
"-" * 52
"`tReporting on {0} modules" -f $varModules.Count
"-" * 52
<#
.SYNOPSIS
Installs base VSCode Extensions
.DESCRIPTION
Uses list of recommended extensions to start using VSCode with PowerShell.
.NOTES
===========================================================================
Created with: Visual Studio Code
Created on: 08.12.2018
Created by: Kavanagh, John J.