Skip to content

Instantly share code, notes, and snippets.

@roysubs
roysubs / what-function
Last active April 7, 2024 20:18
Try to give meaningful information about any Variable, Cmdlet, Function, Alias, External Script, Application
# Find definitions for any Cmdlet, Function, Alias, External Script, Application, or Variable
function what {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[ArgumentCompleter({ [Management.Automation.CompletionResult]::Command })]
$cmd,
[switch]$Examples
)
# Previously declared $cmd as [string]$cmd but this was wrong as cannot then handle arrays or anything else
@roysubs
roysubs / notes-downloading.ps1
Created November 29, 2019 23:03
Notes: download methods
# How do I download URL content using Get-Content in PowerShell Script?
# Assumes that you have a URL on each line in C:\Urls.txt. It will put the files in a folder at C:\UrlOutput. If that’s not where you want them, just change the $OutputFolder variable value appropriately.
$Urls = Get-Content "C:\Urls.txt"
$OutputFolder = "C:\UrlOutput"
if(!(Test-Path $OutputFolder)){ New-Item -ItemType Directory -Path $OutputFolder -Force | Out-Null }
for ($x = 0; $x -lt ($Urls | measure | select -expand Count); $x++)
{
@roysubs
roysubs / Custom-Tools.psm1
Last active April 7, 2024 20:20
Custom-Tools Module to copy into C:\Program Files\WindowsPowerShell\Modules\Custom-Tools
####################
#
# Custom-Tools.psm1
# Current Version: 2020-10-24
#
# Module is installed to the Module folder visible to all users (but can only be modified by Administrators):
# C:\Program Files\WindowsPowerShell\Modules\Custome-Tools
#
# The Module contains only functions to access on demand as required.
# mods : View all Modules installed in all PSModulePath folders.
@roysubs
roysubs / ProfileExtensions.ps1
Last active April 7, 2024 20:20
Called from $profile to add functionality to console settings
########################################
#
# ProfileExtensions.ps1
#
# The profile extensions is normally called by a single line that is added to
# the end of $Profile, or can be dotsourced manually if required.
#
# The handler line in $Profile performs the following:
# a) It check if $($Profile)_extensions.ps1 exists, if not download it.
# b) It then runs (dotsource) $($Profile)_extensionss.ps1.
@roysubs
roysubs / BeginSystemConfig.ps1
Last active April 7, 2024 20:21
Run this script using iex (Invoke-Expression) to configure apps, create profile-extensions, install modules and other custom setup
########################################
#
# BeginSystemConfig.ps1
# iex ((New-Object System.Net.WebClient).DownloadString('https://bit.ly/2R7znLX'));
#
# Author: roysubs@hotmail.com
#
# 2019-11-25 Initial setup
# 2020-10-19 Latest Version
#
@roysubs
roysubs / Git-dump
Last active April 7, 2024 20:22
Git basics dump ...
Just some notes on git ...
Install git from git-scm.com
https://www.youtube.com/watch?v=SWYqp7iY_Tc
https://guides.github.com/activities/hello-world/ # Quick guide from GitHub
Create folder and put stuff in it.
# git init
# git add <filename> # add <filename>
# git add . # add all files in folder
# git status # show added / not added / changed files
@roysubs
roysubs / Basic-Tools.psm1
Last active April 7, 2024 20:22
PowerShell Module with constantly updated set of general tools
####################
# Isolate as much as possible away from $profile. All functions should be in Modules whenever possible
####################
# Module: Common-Tools
# Collection of helper functions to constantly update
function syntax($cmd) { Get-Command $cmd -Syntax } # or (Get-Command $cmd).Definition
function parameter($cmd, $parameter) { Get-Help $cmd -Parameter $parameter }
function examples($cmd) { Get-Help $cmd -Examples } # or (Get-Command $cmd).Definition
@roysubs
roysubs / Get-Gist.ps1
Last active April 7, 2024 20:22
Get-Gist, not working yet
# https://github.com/dfinke/Posh-Gist
# Get-Gist
# Copy of the Gist-Functions, with focus on Get-Gist
# You need a GitHub account to post a gist, this does not support anonymous posts.
# Remember that the param statement should be the first one in a PowerShell script.
param(
[Parameter(Mandatory)]
[string]$User,
@roysubs
roysubs / Send-Gist.ps1
Created November 24, 2019 04:27
Description for Send-Gist.ps1
# https://github.com/dfinke/Posh-Gist
# Send-Gist
# Copy of the Gist-Functions, with focus on Send-Gist
# You need a GitHub account to post a gist, this does not support anonymous posts.
# Remember that the param statement should be the first one in a PowerShell script.
param([string]$Path, [string]$Description)