|

FEATURED POSTS

How to Change Outlook Password in 3 Different Ways

How to Change Outlook Password in 2 Easy Steps

Introduction Before you change your Outlook Password you have to first change it with your email provider. The reason...
spotify web player not working

Spotify Web Player Not Working [Fixed]

Introduction Spotify Web Player may stop working for you with the following error messages: "Spotify Web Player an Error...
DISM.exe /Online /Cleanup-Image /Restorehealth

DISM.exe /Online /Cleanup-Image /Restorehealth Explained

What is DISM.EXE /Online /Cleanup-image /RestoreHealth? "DISM.exe /Online /Cleanup-Image /Restorehealth" is a DISM command that repairs issue with the...
DHCP Relay agent

DHCP Relay Agent: Configuration in Windows Server 2016

What is a DHCP Relay Agent? A DHCP Relay Agent allows DHCP clients in a different network subnet to...
ForEach-Powershell

PowerShell ForEach: Syntax, Parameters, Examples

What is PowerShell ForEach? PowerShell ForEach (ForEach PowerShell) is a PowerShell construct used in iterating through values in a...

TRENDING POSTS

Remote Desktop Connection

Remote Desktop Connection an Internal Error Has Occurred [Fixed]

Introduction I recently received the error message "Remote Desktop Connection an Internal Error Has Occurred". It was strange because...

Find My Samsung: Register and Use Samsung Find my Mobile

Introduction Ever wondered how you could find your Samsung phone if you lost it? Find my Samsung or Samsung...
PowerShell vs CMD

Powershell vs CMD: Differences and Similarities Compared

Introduction This short guide compares PowerShell vs CMD (Windows command prompt). I will cover the history and nature of...
Spotify No Longer Supports this Version of Microsoft Edge

Spotify No Longer Supports this Version of Microsoft Edge [Fixed]

Introduction When you open Spotify web player on Microsoft Edge, you may receive the error message "Spotify No Longer...
Windows 10 Won't Boot

Windows 10 Won’t Boot With Black Screen? 3 Ways to Fix It

Why Won't Windows 10 Boot Up? If your Windows 10 stops with a black screen, the first question in...

BEST OF ITECHGUIDES

spotify web player not working

Spotify Web Player Not Working [Fixed]

Introduction Spotify Web Player may stop working for you with the following error messages: "Spotify Web Player an Error...

Excel Substring: How to Get (Extract) Substring in Excel

Introduction An Excel substring is a portion of a text in a cell. For instance, if a cell contains...
Active Directory FSMO Roles

Active Directory FSMO Roles Explained

Introduction This article offers a simplified explanation of the 5 Active Directory FSMO (pronounced "FisMO") roles.
active directory interview questions

35 Active Directory Interview Questions and Answers

I have compiled 35 Active Directory interview questions and answers. Where necessary, I have also provided additional information to help you understand...
mobile hotspot greyed out windows 10

Mobile Hotspot Greyed Out on Windows 10, iPhone or Android [Fixed]

Introduction If mobile hotspot is greyed out on windows 10, iPhone or Android it is likely that you do...

RECENT POSTS

how to merge cells in excel

How to Merge Cells in Excel in 2 Easy Ways

Introduction You can merge two Cells in Excel using CONCATENATE function or the “&” (ampersand) operator. Though Excel has...
How to Make a Pivot Table in Google Sheets

How to Make a Pivot Table in Google Sheets

Introduction You can make a Pivot Table in Google Sheets to simplify analysis of complex data. A Pivot Table...
how to make Pivot Table

How to Make a Pivot Table in Excel

Introduction A Pivot Table allows you to analyze, summarize and calculate large data to help find relationships. With a...
RAID 3 (Redundant Array of Independent Disks) Explained

RAID 3 (Redundant Array of Independent Disks) Explained

What is RAID 3? RAID 3 is a RAID implementation that uses striping with a dedicated parity disk....
RAID 5 vs RAID 6

RAID 5 vs RAID 6: Differences, Benefits and Disadvantages

What is RAID 5 vs RAID 6? RAID 5 and RAID 6 uses striping with distributed parity technique. However,...
concatenate excel

Concatenate in Excel: How to Concatenate Columns and Strings

What is Concatenate in Excel? Concatenate in Excel is joining two strings into one continuous string. You can join...

How to Add in Excel (Excel Sum) with Examples

Introduction There are different ways to add numbers in Excel. You could simply select the cells containing the data....
Excel Count

Excel Count: How to Count in Excel With Examples

Introduction Excel COUNT Function is used for counting items in a worksheet. Excel COUNT also has the conditional function,...
powershell.exe -command

Powershell.exe Command: Syntax, Parameters and Examples

Introduction You may be wondering why write on Powershell.exe Command. Are there special commands for Powershell.exe? Yes! When you...
how to move columns in excel

How to Move Columns to Rows and Rows to Columns in Excel

Introduction If you receive some Excel data in columns, you can easily move the columns to rows in Excel...

MUST READ

Amazon Hub

Amazon Hub: Your Definitive Guide to Hub by Amazon

What is Amazon Hub? Amazon Hub provides shoppers with a self-service delivery location to pick up their Amazon packages....
Active Directory Domain Services

Active Directory Domain Services: Installation & Configuration

What is Active Directory Domain Services? Active Directory Domain Services (AD DS) is at the core of Microsoft's Directory...

Windows 7 Safe Mode: How to Start Windows 7 in Safe Mode

Introduction If need to perform some advanced troubleshooting on Windows 7, then you may need to start Windows 7...
PowerShell-NoTypeInformation

Powershell NoTypeInformation: Applications and Examples

Powershell NoTypeInformation: Why So Much Interest? I chose to write on 'Powershell -NoTypeInformation' because so many people ask questions...
Active Directory FSMO Roles

Active Directory FSMO Roles Explained

Introduction This article offers a simplified explanation of the 5 Active Directory FSMO (pronounced "FisMO") roles.

Powershell.exe Command: Syntax, Parameters and Examples

-

Introduction

You may be wondering why write on Powershell.exe Command. Are there special commands for Powershell.exe? Yes! When you begin to script with Powershell you quickly realize that you may need to start Powershell with different options.

This guide covers the general Syntax of the Powershell.exe Command, explains its parameters and conclude with some examples.

Powershell.exe Command Syntax

The syntax of Powershell.exe Command is:

PowerShell[.exe] 
[-EncodedCommand ]
[-ExecutionPolicy ]
[-InputFormat {Text | XML}]
[-Mta]
[-NoExit]
[-NoLogo]
[-NonInteractive]
[-NoProfile]
[-OutputFormat {Text | XML}]
[-PSConsoleFile ]
[ -Version <Windows PowerShell version> ]
[-Sta]
[-WindowStyle ]<style>
[-File <FilePath> [<Args>]]
[-Command { - | <script-block> [-args <arg-array> ] | <string> [<CommandParameters>] } ]
Advertisement

Powershell.exe Command Parameters

This section explains the parameters of Powershell.exe Command Syntax. See the table below:

S/NParameterMeaning
1-EncodedCommand <Base64EncodedCommand>Accepts a base-64-encoded string version of a command. This is useful when you need to submit Powershell commands with complex quotation marks or curly braces
2-ExecutionPolicy <ExecutionPolicy>This parameter sets the default execution policy for the current session. The execution policy is saved in the $env:PSExecutionPolicyPreference. This does not modify the execution policy set in the registry.
3-File <FilePath> [<Parameters>]Specifies a script to run. It accepts the scripts parameters.
4-InputFormat {Text | XML}Describes the format of data sent to PowerShell. Valid values are “Text” (text strings) or “XML”
5-MtaStarts PowerShell using a multi-threaded apartment. Multi-threaded apartment (MTA) is the default for PowerShell 2.0. The default in PowerShell 3.0 is single-threaded apartment (STA)
6-StaStarts Windows PowerShell using a single-threaded apartment
7-NoExitIf specified, PowerShell will not exit after execution
8-NoLogoHides the Copyright information that normally displays when PowerShell starts.
9-NonInteractiveExecutes without presenting an interactive prompt to the user
10-NoProfileStarts without loading the Windows PowerShell profile
11-OutputFormatSets the formatting of the output from Windows PowerShell. Valid values are “Text” or “XML”
12-PSConsoleFile <FilePath>Loads the Windows PowerShell console file specified in <FilePath>
13-Version <Windows PowerShell Version>Starts Windows PowerShell with the specified version. Valid values are 2.0 and 3.0.
14-WindowStyle <Window Style>Sets the window style for the session. Valid values are Normal, Minimized, Maximized and Hidden.
15-CommandExecutes the command specified. The value of Command can be “-“, a string. or a script block. Script blocks must be enclosed in braces ({})
16-Help, -?, /?Displays help for PowerShell.exe. You can use PowerShell.exe -Help, PowerShell.exe -? or PowerShell.exe /?

Powershell.exe Command Examples

In this section I will give some Powershell.exe Command examples.

To start Powershell in version 2.0 and not display the copyright information, use the command below:

PowerShell -version 2.0 -NoLogo
 Powershell.exe Command Examples

The result of the last command (shown above), may not mean anything until you start PowerShell.exe without the -NoLogo parameter.

PowerShell -version 2.0

In the previous image, the above command displays the Windows Copyright information. This is because I did not use the -NoLogo parameter.

In another example, if you want to specify the input and output format, use the command below:

PowerShell -InputFormat text -OutputFormat XML

Here is the result in PowerShell:

powershell.exe command

Since I specified input format as text, I can enter text into powershell.exe command. If you press Enter, PowerShell will return to its prompt.

However, if you specify InputFormat as XML and OutputFormat as text, PowerShell command behaves differently.

PowerShell -InputFormat XML -OutputFormat text

See the result of the above command below:

powershell.exe command

PowerShell.exe -Command Parameter Examples

The -Command parameter is the one of the most versatile PowerShell Parameters. The reason is simple. You can run other PowerShell commands with this parameter. You can also run scripts.

The practical application of these these two scenarios will be demonstrated in the next section. In this section, I will demonstrate how to use PowerShell.exe -Command Parameter.

In my first example, I will show how you can run Get-EventLog with the -Command Parameter.

Here is the command:

PowerShell -Command {Get-EventLog -LogName security}
To run the previous command, you MUST open PowerShell as Administrator

Sometimes you may need to write a string that executes a command. In this instance you will need to use an ampersand operator, & followed by the command as shown below:

PowerShell -Command "& {Get-EventLog -LogName security}"
I have had instances where I had to use the ampersand operator, & before a script can run. This may be required when you schedule a PowerShell script with Windows task scheduler.

PowerShell.exe -EncodedCommand Parameter Examples

As I mentioned in the Parameter section of this guide, the -EncodedCommand parameter is used to specify the Base64encoded string version of a command.

In this example, I will show how to run the command, ‘Get-Childitem “c:\program files”‘ in base-64-encoded string.

To convert the command to a base-64-encoded string, use the steps below:

  • Set a variable for the command:
$normalcommand = 'Get-Childitem "c:\program files" '
  • Next, convert the command into bytes as shown below:
$bytes = [System.Text.Encoding]::Unicode.GetBytes($normalcommand)
  • Then convert the bytes to Base64String:
$encodedCommand = [Convert]::ToBase64String($bytes)
  • Finally, run the the command in Base64String:
powershell.exe -encodedCommand $encodedCommand

Here are the results of the commands in PowerShell:

PowerShell.exe -EncodedCommand Parameter Examples

To see what the Base64String string looks like, run the command below:

 $encodedCommand 

This is how it looks like in PowerShell.

Advertisement

How to Schedule Powershell Script to Run in Task Scheduler

In the last part of this guide I will demonstrate how to schedule a PowerShell script with task scheduler.

In this example, I will schedule Get-FreeDiskSpace script. This script will run weekly and send you a report of free disk spaces on all servers.

Follow the steps below to schedule Get-FreeDiskSpace PowerShell script:

  • Open PowerShell or command prompt. Then type this command and press Enter.
taskschd.msc

This will open Task Scheduler.

How to Schedule Powershell Script to Run in Task Scheduler
  • Right-click Task Scheduler and select Create Task.
How to Schedule Powershell Script to Run in Task Scheduler - create scheduled task
  • Give the task a name. You could also enter a description. Then click Triggers tab.
  • To create a new trigger click New.
A trigger is what makes your task run in Task Scheduler.
  • On the New Trigger page, on the Begin the task drop-down ensure that On a schedule is selected. Then select the frequency. If you select Weekly, then check the box beside the day of the week you want your task to run. Finally, configure Advanced settings. Click Ok. Then, on the Create Task page, click Ok again (Second image below).
  • Next, click the Actions tab.
This is where you enter your PowerShell.exe command.
  • On the Actions tab, click New. On the New Action page, beneath program/script, enter the command below:
PowerShell 
  • Then beside Add arguments (optional), enter the following
-Command { C:\PS\Get-FreeDiskSpace.ps1 }
Your script block must be enclosed in braces ({}) as shown above. You must specify the full path to your script. The path must include the extension .ps1
  • When you finish, click Ok.

Conclusion

PowerShell.exe command is for advanced PowerShell users. I hope I have simplified how to use the various parameters.

If you have any question or comment use the “Leave a Reply” form at the end of the page. You could also share your experience with PowerShell commands.

Other Helpful Guides

Additional Resources and References

YOU MAY ALSO LIKE:

LEAVE A REPLY

Please enter your comment!
Please enter your name here

By using this website you agree to accept our Privacy Policy and Terms & Conditions