Skip to content

Instantly share code, notes, and snippets.

View figueroadavid's full-sized avatar

David Figueroa figueroadavid

View GitHub Profile
@figueroadavid
figueroadavid / PowerShell-XAML-Template.ps1
Last active September 23, 2022 15:53 — forked from QuietusPlus/PowerShell-XAML-Template.ps1
Template: Use PowerShell to launch a .xaml file (MainWindow.xaml) designed within Visual Studio. It automatically removes attributes which are otherwise incompatible, so design in Visual Studio and launch your GUI without any additional steps. The template supports "Windows Presentation Foundation" and "Windows Forms" by default, add additional …
[cmdletbinding()]
param(
[parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]$FilePath
)
# .NET Framework classes
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
# XAML
@figueroadavid
figueroadavid / Remove-BadWinlogonProcess.ps1
Created May 18, 2023 19:38
Kills sessions hung on winlogon.exe; first attempt that uses the command line utilities; works pretty well.
function Remove-BadWinlogonProcess {
[cmdletbinding(SupportsShouldProcess)]
param(
[parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]$ServerName
)
$DiscSessionWithNoName_RegEx = '^\s+(?<ID>\d+)\s+Disc'
$Winlogon_RegEx = '^ system\s+\d+\s+(?<PID>\d+)\s+winlogon'
@figueroadavid
figueroadavid / Remove-BadWinlogon_CIM.ps1
Created May 18, 2023 19:40
Newer version of Remove-BadWinlogonProcess but it uses CIM instead, and also checks for hung fontdrvhost.exe processes
function Remove-BadWinLogon_CIM {
<#
.DESCRIPTION
This function examines the list of winlogon process and compares them to active sessions.
If a winlogon process belongs to an active session, it is left alone. If it is not tied
to an active session, it is removed. The console session is specifically ignored, since it
always has a winlogon process, even though there may not be someone logged into the physical
console of the machine.
.SYNOPSIS
@figueroadavid
figueroadavid / Remove-BadWinlogonSession.ps1
Last active May 18, 2023 20:04
Newest version, Citrix only, but removes all the hung sessions in the farm without attached users and in an 'Application Not Running' state
#Requires -Module Citrix.Broker.Admin.V2
function Remove-BadWinLogonSession {
<#
.DESCRIPTION
This function searches for sessions that are in a NoApps state (Applications Not Running) and
also do not have a BrokeringUserName. This state indicates a session with a hung winlogon.exe
process that is not "owned" by anyone. Sessions in a NoApps state, but have a BrokeringUserName
are valid inactive sessions and are not modified.
Import-Module PSScheduledJob
function Set-DrainAndReboot {
[cmdletbinding()]
param(
[parameter(Mandatory)]
$ComputerName
)
$RebootScriptBlock = @'
$CitrixSessionCount = (Get-CimInstance -Namespace Root\Citrix\hdx -ClassName Citrix_Sessions ).count
$CycleCount = 0
function Show-Xaml {
[cmdletbinding()]
param(
[parameter(Mandatory = $true, ValueFromPipeLineByPropertyName = $true, HelpMessage = 'The path to the XAML file to run')]
[ValidateScript({Test-Path -path $_})]
[string]$FilePath
)
Add-Type -AssemblyName PresentationFramework -ErrorAction SilentlyContinue
Add-Type -AssemblyName PresentationCore -ErrorAction SilentlyContinue
@figueroadavid
figueroadavid / SearchSQL.sql
Created December 5, 2023 13:19
Search a SQL database for all instances of a sub-string
/* Reto Egeter, fullparam.wordpress.com */
DECLARE @SearchStrTableName nvarchar(255), @SearchStrColumnName nvarchar(255), @SearchStrColumnValue nvarchar(255), @SearchStrInXML bit, @FullRowResult bit, @FullRowResultRows int
SET @SearchStrColumnValue = '%searchthis%' /* use LIKE syntax */
SET @FullRowResult = 1
SET @FullRowResultRows = 3
SET @SearchStrTableName = NULL /* NULL for all tables, uses LIKE syntax */
SET @SearchStrColumnName = NULL /* NULL for all columns, uses LIKE syntax */
SET @SearchStrInXML = 0 /* Searching XML data may be slow */
@figueroadavid
figueroadavid / Test-EventSource.ps1
Created January 10, 2024 17:01
Test-EventSource tests a list of machine for a list of eventsources
function Test-EventSource {
<#
.SYNOPSIS
Tests for event sources against a list of computers
.DESCRIPTION
The function uses the [System.Diagnostics.EventLog] object to test the presence of
each event source on each computer
.PARAMETER EventSource
@figueroadavid
figueroadavid / Test-EventSourceByLog.ps1
Created January 10, 2024 17:38
Test multiple logs for different event sources that may or may not be in the registry keys
function Test-EventSourceByLog {
<#
.SYNOPSIS
This tests for multiple sources in multiple eventlogs
.DESCRIPTION
This works regardless of if it exists directly in registry or not.
This is different than the Test-EventSource which uses a dotnet function
to check for all the sources that are directly listed in the registry.
@figueroadavid
figueroadavid / Get-ValidatedCredential.ps1
Created January 18, 2024 13:23
Get-ValidatedCredential - retrieves a credential object, but also validates that it is correct
Function Get-ValidatedCredential {
<#
.SYNOPSIS
Retrieves a credential from the user with the standard Windows dialog, and
then it validates that the password is correct for the account.
.DESCRIPTION
Uses the standard dialog with the option to customize the title, the prompt text, and
to prefill a domain name and user name. The credential is then tested against the domain
to validate that the password is correct. If it is not, the user is prompted again.