Skip to content

Instantly share code, notes, and snippets.

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco feature enable -n allowGlobalConfirmation
choco install firefox
choco install GoogleChrome
choco install visualstudio2019professional
choco install vscode
choco install vscode-powershell
choco install onenote
choco install sql-server-management-studio
@itsthedoc
itsthedoc / Upload-SDWANLicense.ps1
Created August 31, 2019 18:42
Example on logging into SDWAN and uploading a license file
### Start security settings ###
### If server's SSL cert is invalid/not trusted, we need to ignore the cert for Invoke-WebRequest
function Ignore-SSLCertificates
{
$Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler = $Provider.CreateCompiler()
$Params = New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable = $false
$Params.GenerateInMemory = $true
@itsthedoc
itsthedoc / Set-MailboxSMTPAddresses.ps1
Last active June 17, 2019 01:14
Quick example of getting mailboxes and setting addresses
### assuming mailboxes.txt has full primary addresses or primary alias names
$mailboxes = get-content mailboxes.txt
$mailboxes | % {
$name = Get-Mailbox $_ | select -ExpandProperty alias
Set-Mailbox $_ -EmailAddresses SMTP:[email protected],[email protected] -WhatIf
}
@itsthedoc
itsthedoc / Get-FizzBuzz.ps1
Created April 13, 2019 00:47
PowerShell example for FizzBuzz
(1..100) | % {
if (($_ % 5 -eq 0) -and ($_ % 3 -eq 0)) {"FizzBuzz"}
else {
if ($_ % 3 -eq 0) {"Fizz"}
elseif ($_ % 5 -eq 0) {"Buzz"}
else {$_}
}
}
Import-Module SharePointPnPPowerShell2013 -DisableNameChecking
Connect-PnPOnline -Url "https://sharepoint/sites/mainsitepage" -CurrentCredentials # if logged into domain
$list = Get-PnPList -Identity "917d9483-d6c4-4f47-8f88-4beac30df4a1" ## Tip: Use Get-PnPlist with no identity to find your list ID
$context = Get-PnPContext
$web = $context.web
$context.Load($web)
$fields = $list.Fields
$context.Load($fields)
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$items = $list.GetItems($query)
$numbers = @(4..6)
foreach ($num in $numbers) {
$WebRequest = Invoke-WebRequest "http://sonlite.dnr.state.la.us/sundown/cart_prod/cart_con_pshmonprod2?p_beg_date=2018&p_parish_code=0$num"
$results = @()
## Extract the tables out of the web request
$tables = @($WebRequest.ParsedHtml.getElementsByTagName("TABLE"))
$table = $tables[0]
$titles = @()
@itsthedoc
itsthedoc / New-UserMenu.ps1
Created August 2, 2018 08:38
New-UserMenu creates a user selection menu in PowreShell
function Show-Menu
{
param (
[string]$Title = 'My Menu'
)
cls
Write-Host "================ $Title ================"
Write-Host "1: Press '1' for this option."
Write-Host "2: Press '2' for this option."
@itsthedoc
itsthedoc / Start-ProcessExample.ps1
Created February 26, 2018 12:38
Start-ProcessExample
$ProcessParameters = @{
FilePath = "C:\Users\xxx\AppData\Local\UiPath\app-18.1.2\UiRobot.exe"
ArgumentList = @(
'/file:"C:\Users\xxx\Documents\UiPath\test\Main.xaml"'
"/input:`"{'arg1':'$Var'}`""
)
NoNewWindow = $true
Wait = $true
}
Start-Process @ProcessParameters
@itsthedoc
itsthedoc / Get-GoalKickerBooks.ps1
Created January 24, 2018 17:08
PowerShell script to parse books.goalkicker.com and download all PDFs
# Get all books from http://books.goalkicker.com/
$links = Invoke-WebRequest http://books.goalkicker.com/ | Select-Object -ExpandProperty links | where {$_.href -notlike "*tweet*"} | Select-Object -ExpandProperty href | Sort-Object
foreach ($l in $links) {
$books = Invoke-WebRequest http://books.goalkicker.com/$l | Select-Object -ExpandProperty links | Where-Object {$_.href -like "*Pro*.pdf" -and $_.href -notlike "about*" } | Select-Object -ExpandProperty href
foreach ($book in $books) {
Invoke-WebRequest http://books.goalkicker.com/$l/$book -OutFile C:\backup\Learnings\$book
}
Get-ADObject -Filter * -Properties * | where {$_.objectsid -eq "REPLACE-WITH-SID"} | fl cn,objectclass,objectsid