Skip to content

Instantly share code, notes, and snippets.

View figueroadavid's full-sized avatar

David Figueroa figueroadavid

View GitHub Profile
@figueroadavid
figueroadavid / Get-ShortPathName.ps1
Created August 29, 2024 15:41
pInvoke function to retrieve 8.3 shortnames in powershell
function Get-ShortPathName{
Param([string] $path)
$MethodDefinition = @'
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetShortPathNameW", SetLastError = true)]
public static extern int GetShortPathName(string pathName, System.Text.StringBuilder shortName, int cbShortName);
'@
$Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name 'Kernel32' -Namespace 'Win32' -PassThru
$shortPath = New-Object System.Text.StringBuilder(500)
@figueroadavid
figueroadavid / ConvertFrom-DHCPToStatic.ps1
Created March 6, 2024 19:56
Converts an existing DHCP address configuration to a local static IP configuration
function ConvertFrom-DHCPToStatic {
<#
.SYNOPSIS
This script takes an existing DHCP configuration and converts it to a static IP configuration
.DESCRIPTION
The script uses several functions to retrieve the necessary data from the existing configuration,
removes that configuration, and installs the new configuration.
.NOTES
This script was built with the idea that there will only be one "physical" NIC in the server that is up and
running when the script is run. It has not been tested in other scenarios
@figueroadavid
figueroadavid / Backup-ArbitraryPuttyKey.ps1
Created February 29, 2024 23:08
Backs up a user's registry keys for Putty out of HKEY_USERS
function Backup-ArbitraryWinSCPKey {
<#
.SYNOPSIS
This script backups a user's registry keys for WinSCP
.DESCRIPTION
Unlike the Backup-WinSCPKey, this script allows the user to backup an arbitrary user's
WinSCP key out of HKEY_USERS\<usersid>\Software\Martin Prikryl
.NOTES
This does require administrator rights, since the user will be delving into HKEY_USERS.
.PARAMETER SamAccountName
@figueroadavid
figueroadavid / Backup-PuttyKey.ps1
Created February 29, 2024 23:08
Back up the current user's regsitry keys for Putty
function Backup-PuttyKey {
<#
.SYNOPSIS
This script backups a user's registry keys for Putty
.DESCRIPTION
This script backs up the user's registry keys for Putty to a specified directory.
.NOTES
This script does not require any special rights
.PARAMETER ExportDirectory
This is the directory where the exported file will be created.
@figueroadavid
figueroadavid / Backup-ArbitraryWinSCPkey.ps1
Created February 29, 2024 23:07
Backup a user's registry keys for WinSCP from HKEY_USERS
function Backup-ArbitraryWinSCPKey {
<#
.SYNOPSIS
This script backups a user's registry keys for WinSCP
.DESCRIPTION
Unlike the Backup-WinSCPKey, this script allows the user to backup an arbitrary user's
WinSCP key out of HKEY_USERS\<usersid>\Software\Martin Prikryl
.NOTES
This does require administrator rights, since the user will be delving into HKEY_USERS.
.PARAMETER SamAccountName
@figueroadavid
figueroadavid / Backup-WinSCPKey.ps1
Last active February 29, 2024 23:06
Back up the registry keys for WinSCP
function Backup-WinSCPKey {
<#
.SYNOPSIS
This script backups a user's registry keys for WinSCP
.DESCRIPTION
This script backs up the user's registry keys for WinSCP to a specified directory.
.NOTES
This script does not require any special rights
.PARAMETER ExportDirectory
This is the directory where the exported file will be created.
@figueroadavid
figueroadavid / Get-UserSid.ps1
Last active February 29, 2024 22:23
Retrieve a user's SID without the AD Module
function Get-UserSID {
<#
.SYNOPSIS
Retrieves a user's security identifier without the need for the ActiveDirectory Module
.DESCRIPTION
Retrieves a user's security identifier without the need for the ActiveDirectory Module
.PARAMETER samAccountName
The actual samAccountName for the user whose account the SID should be retrieved.
.PARAMETER Domain
This is the domain of the account to be checked. It defaults to the domain of the user
@figueroadavid
figueroadavid / Clear-CitrixDesktopShortcuts.ps1
Created February 1, 2024 12:58
Deletes any desktop shortcuts generated by Citrix Workspace App
function Clear-CitrixDesktopShortcuts {
<#
.SYNOPSIS
Deletes desktop shortcuts that are generated by Citrix Workspace App/Receiver
.DESCRIPTION
The script retrieves all of the shortcuts from the user's desktop folder and checks
each of the .lnk files for a target path that matches 'AppData\Roaming\Citrix\SelfService'.
If the link file matches, the file is deleted.
.NOTES
This uses the wscript.shell object, and the script does release all of the COM objects to prevent memory leaks.
if (-not ('wtsapi' -as [type])) {
Add-Type -ErrorAction SilentlyContinue -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public enum WTS_CONNECTSTATE_CLASS
{
WTSActive,
WTSConnected,
WTSConnectQuery,
@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.