Removing Empty Array Elements (Part 1)

Removing Empty Array Elements (Part 1)

Occasionally you come across lists (arrays) with empty elements. What’s the best way of removing empty elements? Creating a Software Inventory Using the Registry Let’s first focus on a common use case: the code below creates a software inventory by reading the...

Removing Empty Array Elements (Part 1)

Removing BOM from the Unicode Files

Removing BOM from Unicode Text Files Using PowerShell BOM (Byte Order Mask) is a characteristic byte sequence used in some Unicode encoded text files. If you receive text files with BOM that need to be processed by systems not supporting BOM, here is a way how...

Removing Empty Array Elements (Part 1)

Get Text File Encoding

Ensuring Correct Text File Encoding in PowerShell Text files can be stored using different encodings, and to correctly reading them, you must specify the encoding. That’s why most cmdlets dealing with text file reading offer the -Encoding parameter (for example,...

Removing Empty Array Elements (Part 1)

SID of Current User

psconf.eu – PowerShell Conference EU 2019 – June 4-7, Hannover Germany – visit www.psconf.eu There aren’t too many trainings around for experienced PowerShell scripters where…

Removing Empty Array Elements (Part 1)

Finding Windows Universal Unique Identifier (UUID)

Every Windows installation has a unique UUID that you can use to distinguish machines. While computer names can change, the UUID won’t: PS> (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID 4C4C4544-004C-4710-8051-C4C04F443732 Universal Unique Identifier...

Removing Empty Array Elements (Part 1)

Formatting Date and Time (with Culture)

In the previous tip we illustrated how Get-Date can take a format string and convert DateTime values to strings. The string conversion always uses your local language though. That might not always be what you need. Let’s check out the problem, and a solution for it:...

Removing Empty Array Elements (Part 1)

Sending PowerShell Results to PDF (Part 1)

Using Microsoft Print to PDF from PowerShell Windows 10 and Windows Server 2016 finally come with a built-in PDF printer called “Microsoft Print to PDF” that you can use from PowerShell to create PDF files. Run this to check your PDF printer: $printer = Get-Printer...

Removing Empty Array Elements (Part 1)

Using FileSystemWatcher Correctly (Part 2)

Understanding the FileSystemWatcher and Its Limitations In the previous tip we introduced the FileSystemWatcher and illustrated how it can miss filesystem changes when your handler code takes too long. How to Use FileSystemWatcher Correctly To use the...

Removing Empty Array Elements (Part 1)

Using FileSystemWatcher Correctly (Part 1)

A FileSystemWatcher can monitor a file or folder for changes, so your PowerShell code can immediately be notified when new files are copied to a folder, or when files are deleted or changed. Example of Synchronous Monitoring Often, you find example code for...

Removing Empty Array Elements (Part 1)

Using Solid Alternatives for $MyInvocation

Lines like $MyInvocation.MyCommand.Definition can be useful to determine the folder in which the current script is stored, i.e. to access other resources located in the same folder. Easier Alternatives Since PowerShell 3 However, ever since PowerShell 3, there have...

Using Custom Styles in RAD Studio 10.3

Using Custom Styles in RAD Studio 10.3

How to Customize Your UI with FireMonkey Styles in RAD Studio 10.3 It’s very easy to customize your user interface using FireMonkey styles in RAD Studio 10.3. We’ve added all of the premium styles to GetIt (Tools > GetIt Package Manager > Styles) in 10.3. This...

Removing Empty Array Elements (Part 1)

Translating VBScript to PowerShell

Most old VBS scripts can be easily translated to PowerShell. The key command in VBS is “CreateObject” which lets you access system libraries. PowerShell translates “CreateObject” to “New-Object -ComObject”, yet the object model and member names stay the same: This VBS...

How to Find and Fix SQL Server Deadlocks

How to Find and Fix SQL Server Deadlocks

Introduction Locking is required for concurrent operations of relational databases to prevent data inconsistency and loss. However, locking impairs the performance of databases. Moreover, the locking process is often complicated. Deadlocks occur when concurrent...

Removing Empty Array Elements (Part 1)

Detecting WinPE

Running PowerShell in WinPE Environments PowerShell can run inside WinPE environments. If you’d like to detect whether your PowerShell script runs inside a WinPE environment, you can simply check whether a special registry key exists: function Test-WinPE { return...

Removing Empty Array Elements (Part 1)

Extract Specific Files from ZIP Archive

Starting with PowerShell 5, cmdlets like Extract-Archive can extract the content of ZIP files to disk. However, you can always extract only the entire archive. Extracting Specific Files Using .NET Methods If you’d rather like to extract individual files, you can...

Removing Empty Array Elements (Part 1)

Running CMD commands in PowerShell

PowerShell by default does not support the native cmd.exe command such as „dir“. Instead, it uses historic aliases called “dir” to point you to the closest PowerShell cmdlet: PS C:\> Get-Command -Name dir | ft -AutoSize CommandType Name Version Source -----------...

Removing Empty Array Elements (Part 1)

Progress Bar Timer

Use the PowerShell progress Bar Here is a simple example using the PowerShell progress bar. The code displays a progress bar counting down a break. Simply adjust the number of seconds you’d like to pause. You could use this example for displaying breaks in classes or...

1 6 7 8 9 10 16