Powershell

Launch a powershell session.

Syntax
      powershell[.exe] [-PSConsoleFile file | -Version version]
         [-NoLogo] [-NoExit] [-NoProfile] [-NonInteractive]
            [-OutputFormat {Text | XML}] [-InputFormat {Text | XML}]
               [-Command { - | script-block [-args arg-array] | string [CommandParameters] } ]

key
 
   -PSConsole File   Load a PowerShell console file. (created with export-console)

   -Version          Start the specified version of Windows PowerShell.

   -NoLog            Hide the copyright banner at startup.

   -NoExit           Do not exit after running startup commands.

   -NoProfile        Do not use the user profile.

   -Noninteractive   Don't present an interactive prompt to the user.

   -OutputFormat     Format the output. Valid values are "Text" (string)
                     or "XML" (serialized CLIXML format).

   -InputFormat      Format of data sent to Windows PowerShell. Valid values are
                     "Text" (string) or "XML" (serialized CLIXML format).  

   -Command          Execute commands or a script file of commands 
                     If Command is "-", the command text is read from standard input.

   -Help, -?, /?     Display Help


Running powershell with -Command will perform the command and then exit, unless -NoExit is specified.
The value of Command can be "-", a string. or a script block.

Script blocks must be enclosed in braces {}

You can specify a script block only when running PowerShell.exe in Windows PowerShell.

The results of the script are returned to the parent shell as deserialized XML objects, not live objects.

If the value of Command is a string, Command must be the last parameter in the command , because any characters typed after the command are interpreted as the command arguments.

To write a string that runs a Windows PowerShell command, use the format: "& {command}"
where the quotation marks indicate a string and the invoke operator (&) causes the command to be executed.

Examples

PowerShell.exe -PSConsoleFile "C:\scripting\MyShell.psc1" -Command ". 'MyScript.ps1'"

Display the security event log:

powershell -command {get-eventlog -logname security}

Or the same thing but calling powershell from the CMD shell:

powershell -command "& {get-eventlog -logname security}"

Related:

List of all powershell commands
Equivalent bash command: bash - launch bash shell



Back to the Top

© Copyright SS64.com 1999-2010
Some rights reserved