Skip to content

Instantly share code, notes, and snippets.

View drlsdee's full-sized avatar
💭
Stop war!

drlsdee

💭
Stop war!
View GitHub Profile
@drlsdee
drlsdee / Get-Win32Service.ps1
Created February 13, 2024 07:10
Get-Win32Service - returns an instance of class Win32_Service including the image path with command line arguments and the service account name
function Get-Win32Service {
[CmdletBinding()]
param (
[Parameter(Mandatory,Position=0)]
[Alias('n')]
[string]
$Name,
[Parameter(Position=1)]
[ValidateSet('Name','Status','ExitCode','DesktopInteract','ErrorControl','PathName',
@drlsdee
drlsdee / Show-PSModuleCommand.ps1
Last active October 24, 2023 14:32
Simply displays a summary of the cmdlets and functions exported from the PowerShell module.
<#
.SYNOPSIS
Simply displays a summary of the cmdlets and functions exported from the PowerShell module.
.DESCRIPTION
Simply displays a summary of the cmdlets and functions exported from the PowerShell module.
.EXAMPLE
PS C:\> Get-Module -Name 'Microsoft.PowerShell.Utility' | Show-PSModuleCommand | Format-Wide -GroupBy Verb -Column 6
Displays a summary of the cmdlets and functions exported from the PowerShell module "Microsoft.PowerShell.Utility".
.INPUTS
[psmoduleinfo]
@drlsdee
drlsdee / Get-TimeStampedFileName.ps1
Created October 24, 2023 06:59
Gets an object of type System.IO.FileInfo and returns the object with generated filename based on the old name and timestamp. May be useful for creating backups, rotating logs etc.
function Get-TimeStampedFileName {
[CmdletBinding()]
[OutputType([System.IO.FileInfo])]
param (
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName,Position=0)]
[Alias('FullName', 'p')]
[System.IO.FileInfo]$Path,
[Parameter(Position=1)]
[Alias('u', 'z')]
@drlsdee
drlsdee / CppHexVersion.psm1
Created April 4, 2023 13:26
Two functions to convert software versions from System.Version to hex string and back
$Script:styles = [System.Globalization.NumberStyles]::AllowHexSpecifier
$Script:formats = [cultureinfo]::InvariantCulture
function ConvertTo-CppHexVersion {
[CmdletBinding()]
[OutputType([string])]
param (
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[Alias('Version')]
[version]
@drlsdee
drlsdee / Split-Array.ps1
Created April 4, 2023 13:06
Just an example of a function that splits the input string into a set of substrings of a given length.
function Split-Array {
[CmdletBinding()]
param (
[Parameter()]
[char[]]
$InputObject,
[Parameter()]
[int]
$PartSize
)
@drlsdee
drlsdee / Get-OldItem.ps1
Created March 30, 2023 09:56
Returns filesystem entries older than N days
function Get-OldItem {
[CmdletBinding()]
[OutputType([System.IO.FileSystemInfo])]
param (
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[Alias('FullName')]
[System.IO.FileSystemInfo]
$Path,
[Parameter()]
[int]
@drlsdee
drlsdee / DotNetLocalizedStringFile.ps1
Created March 29, 2023 06:03
This gist includes a class and functions for checking whether a file (for example, a script or an ADMX template) has an additional file with localized data that matches the specified culture.
#Requires -Version 5.1
class DotNetLocalizedStringFile {
[System.IO.FileInfo]
$SourceFile
[cultureinfo]
$CultureInfo
[System.IO.FileInfo]
$LocalizedFile
[bool]
@drlsdee
drlsdee / Format-Guid.ps1
Created March 17, 2023 13:23
This gist just explains values of IFormatProvider argument of the ToString() method of the .NET type System.Guid. See more: https://learn.microsoft.com/ru-ru/dotnet/api/system.guid.tostring
# This gist just explains values of IFormatProvider argument of the ToString() method of the .NET type System.Guid
# See more: https://learn.microsoft.com/ru-ru/dotnet/api/system.guid.tostring
enum PSGuidFormatProvider {
None = 0 # Only alphanumeric characters: 00000000000000000000000000000000
Braces = 1 # Figure brackets, "{}": {00000000-0000-0000-0000-000000000000}
Dashes = 2 # Hyphens, "-": 00000000-0000-0000-0000-000000000000
Parentheses = 3 # Round brackets, "()": (00000000-0000-0000-0000-000000000000)
Xadecimal = 4 # Groups of heXadecimal values: {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
}
@drlsdee
drlsdee / Set-UriUserInfo.ps1
Created February 17, 2023 08:25
The function appends the username and password, both URL-encoded, to the specified URI. It can be useful for cases where you need to specify a username and password in an HTTP request, and either the username or the password or both contain special characters that need to be escaped.
#Requires -Version 5.1
#Requires -Assembly "System.UriBuilder, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
#Requires -Assembly "System.Web.HttpUtility, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
<#
.SYNOPSIS
The function appends the username and password, both URL-encoded, to the specified URI.
.DESCRIPTION
The function appends the username and password, both URL-encoded, to the specified URI.
It can be useful for cases where you need to specify a username and password in an HTTP request, and either the username or the password or both contain special characters that need to be escaped.
@drlsdee
drlsdee / PSComparers.psm1
Created February 17, 2023 08:13
This PowerShell module contains a set of classes for comparing .NET objects that do not implement the IComparable interface, such as [System.Net.IPAddress], [System.Net.NetworkInformation.PhysicalAddress], [System.Security.Cryptography.Oid], [System.Uri].
#Requires -Version 5.1
<#
This PowerShell module contains a set of classes for comparing .NET objects that do not implement the IComparable interface, such as [System.Net.IPAddress], [System.Net.NetworkInformation.PhysicalAddress], [System.Security.Cryptography.Oid], [System.Uri].
#>
enum PhysicalAddressCase {
Default = 0
UpperCase = 1
LowerCase = 2