http://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx Invoke-Item (II)
Why: Forces the default action to be run on the item.
Invoke-Item *.pdf
The Call Operator &
Why: Used to treat a string as a SINGLE command. Useful for dealing with spaces.
In PowerShell V2.0, if you are running 7z.exe (7-Zip.exe) or another command that starts with a number, you have to use the command invocation operator &.
The PowerShell V3.0 parser do it now smarter, in this case you don’t need the & anymore .
&7z
Invoke-Expression (IEX)
Why: Easy to execute a string. This can be VERY dangerous if used with user input (unless that input has been carefully validated).
$str = "get-process"
Invoke-Expression $str
http://gallery.technet.microsoft.com/scriptcenter/PowerShell-and-7Zip-83020e74
if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {throw "$env:ProgramFiles\7-Zip\7z.exe needed"}
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
sz a -t7z "$directory\$zipfile" "$directory\$name"
[Diagnostics.Process] Start()
[Diagnostics.Process]::Start("notepad.exe","test.txt")
$ps = new-object System.Diagnostics.Process
$ps.StartInfo.Filename = "ipconfig.exe"
$ps.StartInfo.Arguments = " /all"
$ps.StartInfo.RedirectStandardOutput = $True
$ps.StartInfo.UseShellExecute = $false
$ps.start()
$ps.WaitForExit()
[string] $Out = $ps.StandardOutput.ReadToEnd();
Why: Forces the default action to be run on the item.
Invoke-Item *.pdf
The Call Operator &
Why: Used to treat a string as a SINGLE command. Useful for dealing with spaces.
In PowerShell V2.0, if you are running 7z.exe (7-Zip.exe) or another command that starts with a number, you have to use the command invocation operator &.
The PowerShell V3.0 parser do it now smarter, in this case you don’t need the & anymore .
&7z
Invoke-Expression (IEX)
Why: Easy to execute a string. This can be VERY dangerous if used with user input (unless that input has been carefully validated).
$str = "get-process"
Invoke-Expression $str
http://gallery.technet.microsoft.com/scriptcenter/PowerShell-and-7Zip-83020e74
if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {throw "$env:ProgramFiles\7-Zip\7z.exe needed"}
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
sz a -t7z "$directory\$zipfile" "$directory\$name"
[Diagnostics.Process] Start()
[Diagnostics.Process]::Start("notepad.exe","test.txt")
$ps = new-object System.Diagnostics.Process
$ps.StartInfo.Filename = "ipconfig.exe"
$ps.StartInfo.Arguments = " /all"
$ps.StartInfo.RedirectStandardOutput = $True
$ps.StartInfo.UseShellExecute = $false
$ps.start()
$ps.WaitForExit()
[string] $Out = $ps.StandardOutput.ReadToEnd();
No comments:
Post a Comment