Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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…

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

Passing Arguments to Encoded Commands

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

1 6 7 8 9 10 16