Skip to content

Instantly share code, notes, and snippets.

View aev-mambro2's full-sized avatar

André E. Veltstra aev-mambro2

View GitHub Profile
@aev-mambro2
aev-mambro2 / analyze-scheduled-task-run-durations.ps1
Last active September 30, 2021 18:10
analyze-scheduled-task-run-durations
<# Analyze normal run duration of scheduled tasks.
# Gathers insight into how long tasks run, analyzes
# which tasks run shorter or longer than normal,
# reports back to console, and writes out its report
# as a CSV (spreadsheet).
#
# The script assumes that the user account running it
# has access to the computer and is allowed to read its
# event log.
#
@aev-mambro2
aev-mambro2 / check-scheduled-tasks.ps1
Created August 19, 2021 11:52
check-scheduled-tasks
<# Check API Tasks
# This script checks scheduled tasks of all known Windows-operated servers,
# determines whether any has missed its scheduled execution,
# and emails those tasks with server name and amount of missed executions.
#
# Run this after list-api-tasks, which creates the input files that this script
# expects.
#
# Author: A.E.Veltstra
# Version: 2.21.818.1246
@aev-mambro2
aev-mambro2 / list-scheduled-tasks.ps1
Created August 18, 2021 20:07
list-scheduled-tasks
<# List Scheduled Tasks
# This script lists scheduled tasks of all known Windows-operated servers,
# and places each task's path into a file specific to the server.
#
# Run this prior to check-api-tasks, which uses the output files.
#
# Author: A.E.Veltstra
# Version: 2.21.818.1243
#>
@aev-mambro2
aev-mambro2 / import-scheduled-tasks-from-local-folder-structure-to-remote-server.ps1
Created July 19, 2021 18:48
import-scheduled-tasks-from-local-folder-structure-to-remote-server.ps1
$targetServer = "netbui-server-name";
$inputFolder = "C:\Users\Me\Documents\scheduled-task-exports\the-date\$($targetServer)";
$tasksNamespace = "\my\Scheduled\Tasks\Path";
$taskRunnerUserName = "WHO?";
$taskRunnerPassword = "how?";
$c = New-CimSession -ComputerName $targetServer;
Get-ChildItem -Recurse -Path (Join-Path $inputFolder $tasksNamespace) -Filter "*.xml" | foreach {
$newTaskName = $_.BaseName;
$newTaskPath = $_.DirectoryName.Replace($inputFolder,"");
@aev-mambro2
aev-mambro2 / export-scheduled-tasks-from-remote-server-to-local-folder-structure.ps1
Created July 19, 2021 15:36
export-scheduled-tasks-from-remote-server-to-local-folder-structure.ps1
$servers = @{
"netbui-server-name" = @("\task\scheduler\path\*"),
"other-netbui-server" = @(
"\task\scheduler\path1\*",
"\task\scheduler\path2\*",
)
}
$outputFolder = "C:\Users\Me\Documents\scheduled-task-exports\";
foreach ($h in $servers.Keys) {
@aev-mambro2
aev-mambro2 / build.gradle
Last active May 3, 2021 12:59
build.gradle
/*
* Gradle user guide: https://docs.gradle.org/
* Gradle install: https://gradle.org/install/
* Based on Gradle version 5.4.1
* @author A.E.Veltstra
* @since 2.20.0121.1100
* @version 2.21.302.1025
*/
import io.franzbecker.gradle.lombok.task.DelombokTask
@aev-mambro2
aev-mambro2 / get-difference-between-2-lists-of-values-in-tsql.sql
Created April 19, 2021 15:50
Get difference between 2 lists of values in T-SQL
-- Using common table expressions
with
-- Supply list A
a (i) as (select i from (values
('6GA00215S'),
('6GU00208S'),
('6PO00396I'),
('6PO00398I')
) A(i)),
-- Supply list B
@aev-mambro2
aev-mambro2 / keybase.md
Created March 31, 2021 18:08
Keybase Proof

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@aev-mambro2
aev-mambro2 / start-scheduled-task-on-remote-mswindows-server.ps1
Last active March 11, 2021 20:14
How to start a scheduled task on a remote microsoft windows server
<#
# Goal: to run a scheduled task on a remote windows server.
# Requirements: user must have CIM, WMI, and task admin privileges on the remote server.
# (c) 2021, A.E.Veltstra
#>
# Access the remote server. The computer name should be the short NETBUI name, without a domain.
$_session = New-CimSession -ComputerName "NETBUI NAME";
# Point to where the task is stored in the task scheduler. The opening \ points to what the
@aev-mambro2
aev-mambro2 / use-powershell-to-generate-db-regeneration-scripts.ps
Last active July 8, 2024 20:55
use-powershell-to-generate-db-regeneration-scripts
#Based on the article by Phil Factor, 2012, for Redgate:
#https://www.red-gate.com/simple-talk/sql/db-administration/automated-script-generation-with-powershell-and-smo/
Write-Host "This script writes 1 file that contains the SQL to regenerate an SQL Server Database. What file name should the script give it?";
$save_chooser = New-Object -Typename System.Windows.Forms.SaveFileDialog;
$save_chooser.ShowDialog();
$write_output_to=$save_chooser.FileName;
write-host "Saving to: " $write_output_to
$server_instance=(Read-Host -Prompt "Which server?");
$db_name=(Read-Host -Prompt "Which database?");