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 / disable-remote-scheduled-tasks-using-powershell.ps
Last active February 24, 2021 16:02
disable-remote-scheduled-tasks-using-powershell
## This only works if you have CIM, WMI, and task change privileges on the remote host servers.
# List the known hosts, and for each host their known scheduled task paths.
# We're only interested in production task paths - no need to specify test task paths.
# (You did separate those, didn't you?)
#
# The host name is just the NetBUI name: no slashes, ports, protocols, or paths.
# The scheduled task path starts with a backslash (which stands for Task Scheduler -> Task Scheduler Library)
# and then follows the hierarchy you see in the task scheduler. Use a wildcard * to include any task in a path.
$taskHostPaths = @{
@aev-mambro2
aev-mambro2 / use-cte-when-unit-testing-in-tsql.txt
Last active February 4, 2021 20:38
Use Common Table Expressions when Unit Testing in TSQL
Use Common Table Expressions when Unit Testing in TSQL
TSQL, Microsoft's SQL dialect for SQLServer, is capable of executing CTE, also known as Common Table Expression.
We can use these to separate concerns when setting up unit tests, like so, to determine whether a new process
returns the same records as an old process:
WITH old_batch (found) as (SELECT FIELD AS found FROM OLD_QUERY_OR_PROCESS),
new_batch (found) as (SELECT FIELD AS found FROM NEW_QUERY_OR_PROCESS),
compare_old_to_new (found) as (select found from old_batch where found not in (select found from new_batch)),
compare_new_to_old (found) as (select found from new_batch where found not in (select found from old_batch)),
Use IFF for field expressions in TSQL
TSQL, Microsoft's SQL dialect for SQLServer, does not accept simple equations and expressions in place of its fields.
So this it won't execute:
SELECT NAME='aev-mambro2' as Found FROM USERS;
Instead, Microsoft wants us to use IIF as a field expression, like so: