Powershell

Showing MsgBox

Ever wanted to display a dialog box from PowerShell rather than spitting out console text? Then try this function: function Show-MsgBox { param (...

ASCII Table

Here’s a simple way of creating an ASCII table through type casting: 32..255 | ForEach-Object { 'Code {0} equals character {1}' -f $_, [Char]$_ }...

Pipeline Used Or Not?

Sometimes you may want to know if your function received parameters over the pipeline or direct. Here is a way to find out: function test {...

Validate IP Addresses

You can use regular expressions and the –match operator to validate user input. Here’s a loop that keeps asking until the user enters a...

Converting UNIX Time

Surprisingly, when you read some values from the Windows Registry, they do not seem to be in a readable format: $key =...

Finding Disk Controller Errors

This line will analyze your system event log for disk controller errors: PS> Get-EventLog -LogName System -InstanceId 3221487627 -ea 0 |...

Reading Registry Values with Powershell

In a previous tip we presented the functions New-RegKey and Set-RegistryValue to you which made creating registry keys and values very easy. Here is...

Creating Registry Values

In a previous tip we introduced the new function New-RegKey that could create one or more registry keys. Here is a function that creates registry...

Creating Registry Keys

With this new function, it is simple to create new registry keys (including missing parent keys) in all registry hives. All you need are proper...

Listing Domains in Forest

Here is a function that lists all the domains in your forest: function Get-Domain{ $Root = [ADSI]"LDAP://RootDSE" try { $oForestConfig =...

Turning On Standby-Mode

To programmatically enter standby mode, you can use native .NET code like this: function Invoke-Standby { Add-Type -AssemblyName...

Correctly Returning Exit Codes

When you launch a PowerShell script from outside PowerShell, you may want to return an exit code to the caller so that the caller knows if your...

Safely Running PowerShell Scripts

If you want to run a PowerShell script from outside PowerShell, for example from within a batch file, you probably know that you need to prepend...

Recording Audio Text Files

Did you know that PowerShell can record audio messages? All you need is some text. You can then turn the text into spoken language, convert it to a...

Enter Hibernation Mode

Maybe you are running lengthy tasks at night. Sometimes you may want to place the machine into hibernation once your script is done. Here’s a...

Make PowerShell Speak!

By adding a new system type called System.Speech, you can make PowerShell speak out loudly: Add-Type -AssemblyName System.Speech $synthesizer =...

Create Group Policy Reports

Windows Server 2008 R2 comes with the GroupPolicy PowerShell module. You might have to install that feature first before you can use it – run...

Admin Privileges Enabled?

If you want to know whether your script has currently full Administrator privileges, here is an (admittedly long) one-liner that tells you:...

Locking Workstation

If you ever feel the need to lock your interactive session via PowerShell, here’s a function that can do this (and also illustrates how to use...

Logging Off

Stop-Computer and Restart-Computer can shutdown and restart a machine, but there are things they cannot do, for example logging off the current...

Check for 64-bit Environment

In PowerShell v3 (CTP2 publicly available) it is finally a snap to determine whether you are on a 64-bit machine and/or shell. PowerShell 3.0 is...

Stripping Decimals Without Rounding

When you divide numbers and just want the decimals before the decimal point, you could cast the result to integer. However, this would also round...

The Two Faces of -match

The -match operator can be extremely useful because it accepts regular expression patterns and extracts the information that matches the pattern:...

Finding Email of Logged On User

In an Active Directory environment, PowerShell can easily find the currently logged on user and retrieve AD information about that user, for...

Remotely Launching Processes

Unfortunately, the Start-Process cmdlet has no -ComputerName parameter so you cannot use it to launch processes on remote machines. Use WMI instead!...

Keeping Remote Programs Running

When you use PowerShell Remoting (like the Enter-PSSession cmdlet) to connect to another machine and then start a program using Start-Process, the...

1 74 75 76 77 78 104