scripts icon indicating copy to clipboard operation
scripts copied to clipboard

General-purpose PowerShell, F#, and other scripts

Useful General-Purpose Scripts

This repo contains a collection of generally useful scripts (mostly Windows PowerShell).

See PS5 for legacy scripts, syscfg for single-use system config scripts.

PowerShell Scripts

script dependencies

  • Add-CapturesToMatches.ps1: Adds named capture group values as note properties to Select-String MatchInfo objects.

  • Add-Counter.ps1: Adds a incrementing integer property to each pipeline object.

  • Add-DynamicParam.ps1: Adds a dynamic parameter to a script, within a DynamicParam block.

  • Add-GitHubMetadata.ps1: Adds GitHub Linguist overrides to a repo's .gitattributes.

  • Add-NoteProperty.ps1: Adds a NoteProperty to a PSObject, calculating the value with the object in context.

  • Add-ParameterDefault.ps1: Appends or creates a value to use for the specified cmdlet parameter to use when one is not specified.

  • Add-ScopeLevel.ps1: Convert a scope level to account for another call stack level.

  • Add-ScriptCredential.ps1: Serializes a an encrypted credential to a PowerShell script using 32-byte random key file.

  • Add-TimeSpan.ps1: Adds a timespan to DateTime values.

  • :up: Add-VsCodeDatabaseConnection.ps1: Adds a VS Code MSSQL database connection to the repo.

  • Backup-File.ps1: Create a backup as a sibling to a file, with date and time values in the name.

  • Backup-SchTasks.ps1: Exports the local list of Scheduled Tasks into a single XML file.

  • Compare-Properties.ps1: Compares the properties of two objects.

  • Compare-Xml.ps1: Compares two XML documents and returns the differences.

  • Compress-EnvironmentVariables.ps1: Replaces each of the longest matching parts of a string with an embedded environment variable with that value.

  • Connect-SshKey.ps1: Uses OpenSSH to generate a key and connect it to an ssh server.

  • Convert-ChocolateyToWinget.ps1: Change from managing various packages with Chocolatey to WinGet.

  • Convert-ClipboardTsvToHtml.ps1: Parses TSV clipboard data into HTML table data which is copied back to the clipboard.

  • Convert-Xml.ps1: Transform XML using an XSLT template.

  • ConvertFrom-Base64.ps1: Converts base64-encoded text to bytes or text.

  • ConvertFrom-CimInstance.ps1: Convert a CimInstance object to a PSObject.

  • ConvertFrom-DataRow.ps1: Converts a DataRow object to a PSObject, Hashtable, or single value.

  • ConvertFrom-Duration.ps1: Parses a Timespan from a ISO8601 duration string.

  • ConvertFrom-EscapedXml.ps1: Parse escaped XML into XML and serialize it.

  • ConvertFrom-Hex.ps1: Convert a string of hexadecimal digits into a byte array.

  • ConvertFrom-XmlElement.ps1: Converts named nodes of an element to properties of a PSObject, recursively.

  • ConvertTo-Base64.ps1: Converts bytes or text to base64-encoded text.

  • ConvertTo-BasicAuthentication.ps1: Produces a basic authentication header string from a credential.

  • ConvertTo-EpochTime.ps1: Converts a DateTime value into an integer Unix (POSIX) time, seconds since Jan 1, 1970.

  • ConvertTo-LogParserTimestamp.ps1: Formats a datetime as a LogParser literal.

  • ConvertTo-MultipartFormData.ps1: Creates multipart/form-data to send as a request body.

  • ConvertTo-OrderedDictionary.ps1: Converts an object to an ordered dictionary of properties and values.

  • ConvertTo-PowerShell.ps1: Serializes complex content into PowerShell literals.

  • ConvertTo-RomanNumeral.ps1: Convert a number to a Roman numeral.

  • ConvertTo-SafeEntities.ps1: Encode text as XML/HTML, escaping all characters outside 7-bit ASCII.

  • ConvertTo-XmlElements.ps1: Serializes complex content into XML elements.

  • Copy-SchTasks.ps1: Copy scheduled jobs from another computer to this one, using a GUI list to choose jobs.

  • Disable-AnsiColor.ps1: Disables ANSI terminal colors.

  • Enable-AnsiColor.ps1: Enables ANSI terminal colors.

  • Expand-EnvironmentVariables.ps1: Replaces the name of each environment variable embedded in the specified string with the string equivalent of the value of the variable, then returns the resulting string.

  • Export-DatabaseObjectScript.ps1: Exports MS SQL script for an object from the given server.

  • Export-DatabaseScripts.ps1: Exports MS SQL database objects from the given server and database as files, into a consistent folder structure.

  • Export-Fake4TargetsGraph.ps1: Exports a graph of a Fake4 build script's targets.

  • Export-Readme.ps1: Generate README.md file for the scripts repo.

  • Export-TableMerge.ps1: Exports table data as a T-SQL MERGE statement.

  • Find-Comics.ps1: Finds comics.

  • :up: Find-DatabaseValue.ps1: Searches an entire database for a field value.

  • Find-DbColumn.ps1: Searches for database columns.

  • Find-DotNetGlobalTools.ps1: Returns a list of global dotnet tools.

  • Find-DuplicateFiles.ps1: Removes duplicates from a list of files.

  • Find-Indexes.ps1: Returns indexes using a column with the given name.

  • Find-InstalledPrograms.ps1: Searches installed programs.

  • Find-Lines.ps1: Searches a specific subset of files for lines matching a pattern.

  • Find-NewestFile.ps1: Finds the most recent file.

  • Find-ProjectPackages.ps1: Find modules used in projects.

  • Find-SqlDeprecatedLargeValueTypes.ps1: Reports text, ntext, and image datatypes found in a given database.

  • ForEach-Progress.ps1: Performs an operation against each item in a collection of input objects, with a progress bar.

  • Format-ByteUnits.ps1: Converts bytes to largest possible units, to improve readability.

  • Format-Date.ps1: Returns a date/time as a named format.

  • Format-EscapedUrl.ps1: Escape URLs more aggressively.

  • Format-HtmlDataTable.ps1: Right-aligns numeric data in an HTML table for emailing, and optionally zebra-stripes &c.

  • Format-Permutations.ps1: Builds format strings using every combination of elements from multiple arrays.

  • Format-Xml.ps1: Pretty-print XML.

  • Get-AspNetEvents.ps1: Parses ASP.NET errors from the event log on the given server.

  • Get-AssemblyFramework.ps1: Gets the framework version an assembly was compiled for.

  • Get-CachedCredential.ps1: Return a credential from secure storage, or prompt the user for it if not found.

  • Get-CharacterDetails.ps1: Returns filterable categorical information about characters in the Unicode Basic Multilingual Plane.

  • Get-ClassicAspEvents.ps1: Gets Classic ASP errors from the event log on the given server.

  • Get-Comics.ps1: Returns a cached list of comics from the Shortboxed API.

  • :new: Get-CommandParameters.ps1: Returns the parameters of the specified cmdlet.

  • Get-CommandPath.ps1: Locates a command.

  • Get-ConfigConnectionStringBuilders.ps1: Return named connection string builders for connection strings in a config file.

  • Get-ConsoleColors.ps1: Gets current console color details.

  • Get-ConsoleHistory.ps1: Returns the DOSKey-style console command history (up arrow or F8).

  • Get-ContentSecurityPolicy.ps1: Returns the content security policy at from the given URL.

  • Get-Dns.ps1: Looks up DNS info, given a hostname or address.

  • Get-DotNetFrameworkVersions.ps1: Determine which .NET Frameworks are installed on the requested system.

  • Get-DotNetGlobalTools.ps1: Returns a list of global dotnet tools.

  • Get-DotNetVersions.ps1: Get-DotNetVersions.ps1 [<CommonParameters>]

  • Get-EnumValues.ps1: Returns the possible values of the specified enumeration.

  • Get-FrenchRepublicanDate.ps1: Returns a date and time converted to the French Republican Calendar.

  • Get-GitFileMetadata.ps1: Returns the creation and last modification metadata for a file in a git repo.

  • Get-GitFirstCommit.ps1: Gets the SHA-1 hash of the first commit of the current repo.

  • :new: Get-GitHubRepoChildItem.ps1: Adds any missing topics based on repo content.

  • Get-IisLog.ps1: Easily query IIS logs.

  • Get-LibraryVulnerabilityInfo.ps1: Get the list of module/package/library vulnerabilities from the RetireJS or SafeNuGet projects.

  • Get-PocketArticles.ps1: Retrieves a list of saved articles from a Pocket account.

  • Get-RandomBytes.ps1: Returns random bytes.

  • Get-RepoName.ps1: Gets the name of the repo.

  • Get-SslDetails.ps1: Enumerates the SSL protocols that the client is able to successfully use to connect to a server.

  • Get-SystemDetails.ps1: Collects some useful system hardware and operating system details via CIM.

  • Get-Todos.ps1: Returns the TODOs for the current git repo, which can help document technical debt.

  • Get-TypeAccelerators.ps1: Returns the list of PowerShell type accelerators.

  • Get-Unicode.ps1: Returns the (UTF-16) .NET string for a given Unicode codepoint, which may be a surrogate pair.

  • Get-UnicodeName.ps1: Get-UnicodeName.ps1 [-CodePoint] [<CommonParameters>] Get-UnicodeName.ps1 [-Character] [<CommonParameters>]

  • Get-VSCodeSetting.ps1: Sets a VSCode setting.

  • Get-VSCodeSettingsFile.ps1: Gets the path of the VSCode settings.config file.

  • Get-XmlNamespaces.ps1: Gets the namespaces from a document as a dictionary.

  • Hide-Command.ps1: Make a command unavailable.

  • Import-ClipboardTsv.ps1: Parses TSV clipboard data into objects.

  • Import-Variables.ps1: Creates local variables from a data row or dictionary (hashtable).

  • :up: Import-VsCodeDatabaseConnections.ps1: Adds config XDT connection strings to VSCode settings.

  • :up: Invoke-CommandWithParams.ps1: Execute a command by using matching dictionary entries as parameters.

  • Invoke-WindowsPowerShell.ps1: Runs commands in Windows PowerShell (typically from PowerShell Core).

  • Join-FileName.ps1: Combines a filename with a string.

  • Join-Keys.ps1: Combines dictionaries together into a single dictionary.

  • Measure-DbColumn.ps1: Provides statistics about SQL Server column data.

  • Measure-DbColumnValues.ps1: Provides sorted counts of SQL Server column values.

  • Measure-DbTable.ps1: Provides frequency details about SQL Server table data.

  • Measure-Indents.ps1: Measures the indentation characters used in a text file.

  • Measure-StandardDeviation.ps1: Calculate the standard deviation of numeric values.

  • Measure-TextFile.ps1: Counts each type of indent and line ending.

  • Merge-Json.ps1: Create a new JSON string by recursively combining the properties of JSON strings.

  • Merge-PSObject.ps1: Create a new PSObject by recursively combining the properties of PSObjects.

  • Merge-XmlSelections.ps1: Builds an object using the named XPath selections as properties.

  • New-DbProviderObject.ps1: Create a common database object.

  • New-Jwt.ps1: Generates a JSON Web Token (JWT)

  • New-NamespaceManager.ps1: Creates an object to lookup XML namespace prefixes.

  • New-RandomVehicle.ps1: Generates random vehicle details with a valid VIN.

  • New-Script.ps1: Creates a simple boilerplate script.

  • New-Shortcut.ps1: Create a Windows shortcut.

  • Open-Comic.ps1: Opens a comic's PreviewsWorld page.

  • Optimize-Help.ps1: Cleans up comment-based help blocks by fully unindenting and capitalizing dot keywords.

  • Optimize-Path.ps1: Sorts, prunes, and normalizes both user and system Path entries.

  • Push-WorkspaceLocation.ps1: Pushes the current VS Code editor workspace location to the location stack.

  • Read-ChocolateySummary.ps1: Retrieves the a summary from the Chocolatey log.

  • Read-Choice.ps1: Returns choice selected from a list of options.

  • Remove-CachedCredential.ps1: Removes a credential from secure storage.

  • Remove-LockyFile.ps1: Removes a file that may be prone to locking.

  • Remove-NullValues.ps1: Removes dictionary entries with null vaules.

  • Remove-ParameterDefault.ps1: Removes a value that would have been used for a parameter if none was specified, if one existed.

  • Rename-GitHubLocalBranch.ps1: Rename a git repository branch.

  • Rename-Script.ps1: Renames all instances of a script, and updates any usage of it.

  • Repair-DatabaseConstraintNames.ps1: Finds database constraints with system-generated names and gives them deterministic names.

  • Repair-DatabaseUntrustedConstraints.ps1: Finds database constraints that have been incompletely re-enabled.

  • :up: Repair-ScriptStyle.ps1: Accepts justifications for script analysis rule violations, fixing the rest using Invoke-ScriptAnalysis.

  • Reset-ConsoleColors.ps1: Resets console color palette.

  • Resolve-XmlSchemaLocation.ps1: Gets the namespaces and their URIs and URLs from a document.

  • Resolve-XPath.ps1: Returns the XPath of the location of an XML node.

  • Restore-SchTasks.ps1: Imports from a single XML file into the local Scheduled Tasks.

  • Save-PodcastEpisodes.ps1: Saves enclosures from a podcast feed.

  • Save-WebRequest.ps1: Downloads a given URL to a file, automatically determining the filename.

  • Select-CapturesFromMatches.ps1: Selects named capture group values as note properties from Select-String MatchInfo objects.

  • Send-MailMessageFile.ps1: Sends emails from a drop folder using .NET config defaults.

  • Send-SeqEvent.ps1: Send an event to a Seq server.

  • Send-SeqScriptEvent.ps1: Sends an event (often an error) from a script to a Seq server, including script info.

  • Send-SqlReport.ps1: Execute a SQL statement and email the results.

  • Set-ConsoleColors.ps1: Overrides ConsoleClass window color palette entries with RGB values.

  • Set-ConsoleColorTheme.ps1: Overrides ConsoleClass window color palette entries with a preset color theme.

  • Set-JsonProperty.ps1: Sets a property of arbitrary depth in a JSON string.

  • Set-ParameterDefault.ps1: Assigns a value to use for the specified cmdlet parameter to use when one is not specified.

  • Set-RegexReplace.ps1: Updates text found with Select-String, using a regular expression replacement template.

  • Set-VSCodeSetting.ps1: Sets a VSCode setting.

  • Show-DataRef.ps1: Display an HTML view of an XML schema or WSDL using Saxon.

  • Show-Time.ps1: Displays a formatted date using powerline font characters.

  • Split-FileName.ps1: Returns the specified part of the filename.

  • :new: Split-Keys.ps1: Clones a dictionary keeping only the specified keys.

  • Stop-ThrowError.ps1: Throws a better error than "throw".

  • Test-Administrator.ps1: Checks whether the current session has administrator privileges.

  • Test-DateTime.ps1: Tests whether the given string can be parsed as a date.

  • Test-FileTypeMagicNumber.ps1: Tests for a given common file type by magic number.

  • Test-HttpSecurity.ps1: Scan sites using Mozilla's Observatory.

  • Test-Interactive.ps1: Determines whether both the user and process are interactive.

  • Test-Json.ps1: Determines whether a string is valid JSON.

  • Test-Jwt.ps1: Determines whether a string is a valid JWT.

  • Test-LockedFile.ps1: Returns true if the specified file is locked.

  • Test-MagicNumber.ps1: Tests a file for a "magic number" (identifying sequence of bytes) at a given location.

  • Test-NewerFile.ps1: Returns true if the difference file is newer than the reference file.

  • Test-NoteProperty.ps1: Looks for any matching NoteProperties on an object.

  • :up: Test-Range.ps1: Returns true from an initial condition until a terminating condition; a latching test.

  • Test-Uri.ps1: Determines whether a string is a valid URI.

  • Test-USFederalHoliday.ps1: Returns true if the given date is a U.S. federal holiday.

  • Test-Variable.ps1: Indicates whether a variable has been defined.

  • Test-Windows1252.ps1: Determines whether a file contains Windows-1252 bytes that are invalid UTF-8 bytes.

  • Test-Xml.ps1: Try parsing text as XML, and validating it if a schema is provided.

  • Trace-GitRepoTest.ps1: Uses git bisect to search for the point in the repo history that the test script starts returning true.

  • Uninstall-OldModules.ps1: Uninstalls old module versions.

  • Update-Everything.ps1: Updates everything it can on the system.

  • Update-Files.ps1: Copies specified source files that exist in the destination directory.

  • Update-Modules.ps1: Cleans up old modules.

  • Use-Command.ps1: Checks for the existence of the given command, and adds if missing and a source is defined.

  • Use-Java.ps1: Switch the Java version for the current process by modifying environment variables.

  • Use-NetMailConfig.ps1: Use .NET configuration to set defaults for Send-MailMessage.

  • Use-ProgressView.ps1: Sets the progress bar display view.

  • Use-ReasonableDefaults.ps1: Sets certain cmdlet parameter defaults to rational, useful values.

  • Use-SeqServer.ps1: Set the default Server and ApiKey for Send-SeqEvent.ps1

  • Use-SqlcmdParams.ps1: Use the calling script parameters to set Invoke-Sqlcmd defaults.

  • Write-VisibleString.ps1: Displays a string, showing nonprintable characters.

F# Scripts

Office VBA Scripts

  • OutlookExpireTag.vba: Too many emails remain beyond their period of relevance: daily personnel schedule changes, found item notices, office food notices, server reboot notices, weather/traffic warnings, &c. This Outlook script will allow specifying an expiration date as a hashtag in the subject of outgoing emails, since Outlook does such a good job of hiding the UI for that field. -BL
  • OutlookPasteFormattedIndented.vba: Outlook will strip single-space indents when displaying emails. If you've got, for example, syntax highlighted source code that employs any indentation of only one space, you'll want to add two spaces to the each line (adding one will not appear for text that isn't indented). This Outlook script will paste formatted text, and indent it. Requires Tools -> References -> Microsoft Word 14.0 Object Library (later versions may also work)
  • OutlookPasteTsvTable.vba: This Outlook VBA Sub can be connected to a toolbar button for pasting TSV data as an attractive, formatted table. -BL Requires Tools -> References -> Microsoft Word 14.0 Object Library (later versions may also work)