• Narrow screen resolution
  • Wide screen resolution
  • Increase font size
  • Decrease font size
  • Default font size
  • default color
  • red color
© Diana Scherff, Amas-Veritas.com

Welcome to Amas Veritas [dot] com

Updates: Media (lyrics) has a new layout. I could never figure out how to lay it out, but it's easier to navigate now. I'm still working on a better duplicate Mamblog mod. I'm trying to make submittions easier but the poetry form died for some reason. Quizzes are also on their way from the old site. Joomla content isn't very code friendly so I'm having to rewrite old code. You can still click on News > AH v21 > Screen if you wish to use the quizzes.
 
Home arrow Tools arrow Software arrow Invoke-Expression [iex]
Invoke-Expression [iex] Print E-mail
Written by Diana, on 04-09-2007 02:36
Views 135    
Favoured None

PS C:\Users\Admin> help iex -full

NAME
    Invoke-Expression

SYNOPSIS
    Runs a Windows PowerShell expression that is provided in the form of a string.

SYNTAX
    Invoke-Expression [-command] <string> [<CommonParameters>]


DETAILED DESCRIPTION
    Runs a Windows PowerShell expression that is provided in the form of a string. Invoke-Expression outputs the result of the command specified as the value of the Command parameter. However, if the result is an empty array, it outputs $null and, if the result is a single-element array, it outputs that single element.


PARAMETERS
    -command <string>
        Specifies a literal string or a variable that contains a string that is a valid Windows PowerShell expression.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet snpports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".


INPUT TYPE
    None


RETURN TYPE
    The output of the cmdlet is usually of the same type as the result of executing the expression represented by the string specified as the value of the Command parameter. If, however, the output of the expression is an empty array or a single-element array, then the output from the cmdlet is $null or the single element, respectively.


NOTES


        To provide a script block as the value of the Command parameter, you must include it within quotation marks. Otherwise, the shell will recognize the script block and evaluate it rather than pass it in a literal form as the value of the Command parameter. For more information about script blocks, type get-help about_script_block.

        Using the invoke-expression cmdlet, without taking the proper precautions, could compromise the security of your computing environment. This cmdlet makes it easy to write scripts that accept input that is then used to construct and run Windows PowerShell commands. The author of such a script does not have complete control over the commands the script can run. Some of the input provided to the script could represent malicious commands. Those commands will be run (under the current security context of the script) unless the script author has been careful to validate all input before using it. In general, it is best to identify and allow a set of known good input and reject all other input, rather than allow all input except that which appears to be malicious.


    ----------------- EXAMPLE 1 -----------------

    C:\PS>$sorted_processes = "get-process | sort-object Name"
    invoke-expression $sorted_processes


    This command creates a variable named $sorted_processes and stores the text of a command in that variable. The invoke-expression cmdlet is then used to run the command stored in the sorted_processes variable.





    ----------------- EXAMPLE 2 -----------------

    C:\PS>$cmdlet_name = "get-eventlog"
    $example_number = 1
    $example_code = (get-help $cmdlet_name).examples.example[($example_number-1)].code
    invoke-expression $example_code


    This command retrieves and runs an example command from cmdlet help. It runs the first example for the Get-EventLog cmdlet. To run an example for a different cmdlet, change the value of the $cmdlet_name variable to the name of the cmdlet and change the $example_number variable to the example number you want to run. The command will fail if the example number you enter is not valid.

    The first line of the command stores the name of a cmdlet, get-eventlog, in the $cmdlet_name variable. The second line of the command stores the example number in the $example_number variable. In thn third line of the command, properties of the object returned by the Get-Help cmdlet are accessed to retrieve the example code and store it in the $example_code variable. In the last line of the command, the example code is run using Invoke-Expression.






RELATED LINKS
    Trace-Command
    Invoke-Item
    Invoke-History


Last update: 04-09-2007 02:36

Published in : Tools, Windows PowerShell

Users' Comments (0) RSS feed comment

No comment posted

Add your comment



mXcomment 1.0.4 © 2007-2009 - visualclinic.fr
License Creative Commons - Some rights reserved
 
< Prev   Next >




Double click any word on this page for a definition.
Using Firefox? Enable definitions by downloading the extension.
Sorry, this feature does not currently work in Opera or Safari.

No Users Online

Statistics

OS: FreeBSD
PHP: 5.2.1
MySQL: 4.1.21-log
Time: 21:52
Caching: Disabled
GZIP: Disabled
Members: 36
News: 2448
Web Links: 39
Visitors: 1443526

Syndicate

Login

Particls