24/7/365 Support

Windows

Display the Properties of an Item As a List in Windows PowerShell

Problem

You have an item (for example, an error record, directory item, or .NET object), and you want to display detailed information about that object in a list format.

Solution

To display detailed information about an item, pass that item to the FormatList cmdlet. For example, to display an error in list format, type the commands:

$currentError = $error[0] $currentError | FormatList Force

Discussion

How to Record a Transcript of Your in Windows PowerShell Session

Problem

You want to record a log or transcript of your shell session.

Solution

To record a transcript of your shell session, run the command StartTranscript Path. Path is optional and defaults to a filename based on the current system time. By default, PowerShell places this file in the My Documents directory. To stop recording the transcript of your shell system, run the command StopTranscript.

Discussion

Add Information to the End of a File in Windows PowerShell

Problem

You want to redirect the output of a pipeline into a file but add the information to the end of that file.

Solution

To redirect the output of a command into a file, use either the Append parameter of the OutFile cmdlet, or one of the appending redirection operators. Both support options to append text to the end of a file.

OutFile:

GetChildItem | OutFile Append files.txt

Redirection operators:

GetChildItem >> files.txt

Discussion

Store the Output of a Windows PowerShell Command into a File

Problem

You want to redirect the output of a pipeline into a file.

Solution

To redirect the output of a command into a file, use either the OutFile cmdlet or one of the redirection operators.

OutFile:

GetChildItem | OutFile unicodeFile.txt GetContent filename.cs | OutFile Encoding ASCII file.txt GetChildItem | OutFileWidth 120 unicodeFile.cs

Redirection operators:

GetChildItem > files.txt GetChildItem 2> errors.txt

Discussion

Access and Manage Your Console History in Windows PowerShell

Problem

After working in the shell for awhile, you want to invoke commands from your history, view your command history, and save your command history.

Solution

To get the most recent commands from your session, use the GetHistory cmdlet:

GetHistory

To rerun a specific command from your session history, provide its Id to the InvokeHistory cmdlet: InvokeHistory Id

Program: Learn Aliases for Common Windows Shell Commands

In interactive use, full cmdlet names (such as GetChildItem) are cumbersome and slow to type. Although aliases are much more efficient, it takes awhile to discover them. To learn aliases more easily, you can modify your prompt to remind you of the shorter version of any aliased commands that you use.

This involves two steps:

1. Add the program, GetAliasSuggestion.ps1, to your tools directory or other directory.

Example 19. GetAliasSuggestion.ps1

Customize the Windows Shell to Improve Your Productivity

Problem

You want to use the PowerShell console more efficiently for copying, pasting, history management, and scrolling.

Solution

Shell console windows and make many tasks easier.

Example 18. SetConsoleProperties.ps1

PushLocation SetLocation HKCU:\Console NewItem '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe' SetLocation '.\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe'

Measure the Duration of a Windows PowerShell Command Problem

You want to know how long a command takes to execute.

Solution

To measure the duration of a command, use the MeasureCommand cmdlet: PS >MeasureCommand { StartSleep Milliseconds 337 }

Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 339 Ticks : 3392297 TotalDays : 3.92626967592593E06 TotalHours : 9.42304722222222E05 TotalMinutes : 0.00565382833333333 TotalSeconds : 0.3392297 TotalMilliseconds : 339.2297

Discussion

Determine the Status of the Last Windows PowerShell Command

Problem

You want to get status information about the last command you executed, such as whether it succeeded.

Solution

Use one of the two variables PowerShell provides to determine the status of the last command you executed: the $lastExitCode variable and the $? variable.

$lastExitCode

Anumber that represents the exit code/error level of the last script or application that exited

$? (pronounced “dollar hook”)

A Boolean value that represents the success or failure of the last command

Discussion

How to Get the System Date and Time in Windows PowerShell

Problem

You want to get the system date.

Solution

To get the system date, run the command GetDate.

Discussion

The GetDate command generates rich objectbased output, so you can use its result for many daterelated tasks. For example, to determine the current day of the week:

PS >$date = GetDate PS >$date.DayOfWeek Sunday

For more information about the GetDate cmdlet, type GetHelp GetDate.

Pages

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say