Skip to content

Instantly share code, notes, and snippets.

View jkavanagh58's full-sized avatar

John J Kavanagh jkavanagh58

View GitHub Profile
Function Remove-CodeConfig {
<#
.NOTES
08.12.2018 JJK: TODO: Add the Whatif component of ShouldSupportProcess
#>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Medium')]
Param ()
# Check for existing config and data
If (Test-Path $env:APPDATA\Code -ErrorAction SilentlyContinue){
# Remove from AppData
Extension Name Priority Comments
PowerShell 1 Goes without saying
PrintCode 3 If you share code via email and any copy/paste
BlackBoard 3 If you like dark themes I prefer this one
Share Code 2 Much betterr to share and post code
Bracket Pari Colorizer 2 Very helpful for script editing and debugging
Visual Studio Team Services
<#
.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.
Function show-installedmodules {
#Requires -Version 5
[CmdletBinding()]
Param(
$varModules = (get-installedmodule)
)
Begin {
"-" * 52
"`tReporting on {0} modules" -f $varModules.Count
"-" * 52
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 {
<#
.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
{
"Condition statement": {
"prefix": "cond",
"body": [
"${_} { ${0}; break }"
],
"description": "Switch condition statement"
},
"Credential Parameter": {
"prefix": "credparam",
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}} |
$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."
# 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}}