Skip to content

Instantly share code, notes, and snippets.

View potatoqualitee's full-sized avatar
big permz energy

Chrissy LeMaire potatoqualitee

big permz energy
View GitHub Profile
@potatoqualitee
potatoqualitee / auto.ps1
Created May 19, 2020 07:15
Windows Services Recovery for SQL Server
$servers = 'sql01','sql02','sql03'
foreach ($server in $servers) {
Invoke-Command -ComputerName $server -ScriptBlock {
$services = Get-CimInstance -ClassName 'Win32_Service' | Where-Object {
$_.description -match 'sql' -and $_.StartMode -match 'Auto'
}
foreach ($service in $services) {
sc.exe failure $service.name reset= 86400 actions= restart/5000/restart/10000/restart/10000/
}
@potatoqualitee
potatoqualitee / replacebuiltin.ps1
Last active February 24, 2021 15:17
Update PackageManagement, PowerShellGet
# save the newest versions of PackageManagementand PowerShellGet
mkdir C:\temp\psmods
Save-Module PackageManagement, PowerShellGet -Path C:\temp\psmods
# restart the console so that the DLLs are removed from memory and the directories can be removed
exit
# start powershell as administrator
$paths = "C:\Program Files\WindowsPowerShell\Modules\PackageManagement", "C:\Program Files\WindowsPowerShell\Modules\PowerShellGet"
@potatoqualitee
potatoqualitee / findshit.ps1
Created February 5, 2020 16:25
findshit.ps1
function findshit ($str) {
$str = [regex]::escape($str)
Select-String -Pattern $str -Path (Get-ChildItem C:\github\dbatools\*.ps* -Recurse -Exclude 'allcommands.ps1', '*.dll', "*psproj")
}
@potatoqualitee
potatoqualitee / answers.md
Last active May 7, 2023 11:46
answers.md

Something we appreciate about PowerShell and dbatools is that there are often a number of perfectly valid ways to solve the same problem. Considering this, some of the questions have multiple answers.

Some answers are different ways to express the same solution.

Chapter 2

Find all commands that have DbaReg in their name.

Get-Command *dbareg* -Module dbatools
# or
@potatoqualitee
potatoqualitee / Export-FileIcon.ps1
Created January 29, 2020 21:22
Export-FileIcon.ps1
Function Export-FileIcon {
<#
.SYNOPSIS
Export-FileIcon exports high-quality icons stored within .DLL and .EXE files.
.DESCRIPTION
Export-FileIcon exports high-quality icons stored within .DLL and .EXE files. The function can export to a number of formats, including
ico, bmp, png, jpg, gif, emf, exif, icon, tiff, and wmf. In addition, it can also export to a different size.
# thanks https://stackoverflow.com/a/36716601/2610398
function Import-ModuleRemotely {
param (
[string]$ModuleName = "xWindowsUpdate",
[System.Management.Automation.Runspaces.PSSession]$Session
)
begin {
function Exports ([string] $paramName, $dictionary) {
if ($dictionary.Keys.Count -gt 0) {
$keys = $dictionary.Keys -join ","
@potatoqualitee
potatoqualitee / NOT DONE YET.ps1
Last active January 29, 2020 21:23
NOT DONE YET.ps1
function Initialize-DbDisks {
<#
.SYNOPSIS
Hello
.DESCRIPTION
VMware only, and Windows and Mount points
.PARAMETER Path
The Path to the STIG xml file. Not required, as they've been included.
@potatoqualitee
potatoqualitee / Invoke-WsusDbQuery.ps1
Created August 1, 2019 09:13
Create a connection to a WSUS database using PowerShell
# No longer used but didn't want to throw it away.
function Invoke-WsusDbQuery {
[CmdletBinding()]
param (
[string]$ComputerName = $script:WsusServer,
[PSCredential]$Credential = $script:WsusServerCredential,
[string]$Pattern,
[string]$UpdateId,
[switch]$EnableException
)
@potatoqualitee
potatoqualitee / Save-KBFile.ps1
Last active June 7, 2024 17:48
Download Windows patch files / KB (patchid like KBxxxxx) and save them to disk using PowerShell
function Save-KBFile {
<#
.SYNOPSIS
Downloads patches from Microsoft
.DESCRIPTION
Downloads patches from Microsoft
.PARAMETER Name
The KB name or number. For example, KB4057119 or 4057119.
@potatoqualitee
potatoqualitee / gallery.ps1
Created February 2, 2019 13:04
deployment script