Using a Queue instead of a Recursion

Using a Queue instead of a Recursion

Rather than calling functions recursively, you may at times want to use a Queue object that you can load with fresh tasks while you are unloading things that you have already processed. Searching a Filesystem Without Recursion Lee Holmes has recently posted the below...

Using a Queue instead of a Recursion

Locking the Screen with PowerShell

Here is a PowerShell function called Lock-Screen that can lock the screen and prohibit user interaction. There can be a custom message, and the screen can be dimmed during lockout. Here is an example call: PS> Lock-Screen -LockSeconds 4 -DimScreen -Title 'Go away...

The Impact of Cloud on DBA

The Impact of Cloud on DBA

The DBA is the information technology professional responsible for ensuring the ongoing operational functionality and efficiency of an organization’s databases and the applications that access those databases. Traditionally, the job has entailed becoming an...

Using a Queue instead of a Recursion

Passing Arguments to Encoded Commands

Why Encode PowerShell Code? Encoding PowerShell code is a great way to run PowerShell code outside the PowerShell environment, i.e. in batch files. Here is some sample code that takes PowerShell code, encodes it, and shows how to run it with a console command:...

Using a Queue instead of a Recursion

Deleting Registry Keys that can’t be Deleted

Why Some Registry Keys Can't Be Deleted in PowerShell Deleting registry keys is typically trivial and can be done with Remove-Item. However, every once in a while, you may come across registry keys that can’t be deleted. In this tip we’ll show an example, and provide...

Using a Queue instead of a Recursion

Splitting Large Files in Smaller Parts (Part 1)

PowerShell can split large files in multiple smaller parts, for example to transfer them as email attachments. Today, we focus on splitting files. In our next tip, we show how you can join the parts back together. Splitting Large Files into Smaller Parts with...

Using a Queue instead of a Recursion

Using Custom Prompts for Mandatory Parameters

How PowerShell Handles Mandatory Parameters When you define mandatory parameters in PowerShell, the user gets prompted for the value if it is missing. The prompt uses the parameter name only as you can see when you run this code: param ( [Parameter(Mandatory)]...

Using a Queue instead of a Recursion

Calculating Most and Least Significant Byte

Numbers are stored internally as bytes. An Int32 value, for example, uses four bytes. Sometimes it is required to split up the number into its byte parts, for example, to calculate checksums with the least significant byte. Guide to Handling Numbers in Bytes We have...

Using a Queue instead of a Recursion

Create ASCII Art

It’s amazing how versatile PowerShell is: with just a couple of lines of code, you can turn any photo and image into a piece of ASCII art. PowerShell simply loads the image, then scans it line by line and row by row, and replaces each pixel with an ASCII character,...

Using a Queue instead of a Recursion

Verifying Local User Account Passwords

In the previous tip, we asked Active Directory to validate user account passwords. The same can be done with local accounts. Your PowerShell code can use local account passwords to manage access to scripts or partial script functionality. Of course, you could also use...

Using a Queue instead of a Recursion

Converting Text to Image

What is WPF (Windows Presentation Foundation)? WPF (Windows Presentation Foundation) is not just a technique to create UIs. You can create any type of vector-based graphics composition and save it to a graphics file. Here is a simple example that takes any text and...

Using a Queue instead of a Recursion

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...

Using a Queue instead of a Recursion

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...

Using a Queue instead of a Recursion

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,...

Using a Queue instead of a Recursion

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…

Using a Queue instead of a Recursion

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...

Using a Queue instead of a Recursion

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:...

Using a Queue instead of a Recursion

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...

Using a Queue instead of a Recursion

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...

1 6 7 8 9 10 16