SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 781 | Next

David A. Karp

"Windows Vista Annoyances: Tips, Secrets, and Hacks"


Variables can also be used with object references, just like in WSH scripts
(see ???Object References,??? earlier in this chapter). PowerShell even makes use
of some of the same objects as WSH, like this one:
$WshShell = New-Object -ComObject WScript.Shell
This means you can use this object to do things like access the Registry or
create shortcuts. For instance, once the $WshShell object has been initialized,
try this:
$lnk = $WshShell.CreateShortcut("$Home\Desktop\Solitaire.lnk")
$lnk.TargetPath = "%ProgramFiles%\Microsoft Games\Solitaire\Solitaire.exe"
$lnk.Save( )
which creates another object reference, $lnk, applies characteristics to it,
and then saves it to a file. Note some subtleties:
??? The preset $Home variable conveniently contains the full path of the current
user??™s home folder.
??? The quotation marks are significant in that if you were to substitute the
"double" quotes with 'single' quotes, PowerShell would not interpret
your variables, but rather leave them literally as you??™ve typed them.
??? The %ProgramFiles% environment variable??”a separate entity from
PowerShell variables??”is explained in ???Variables and the Environment,???
earlier in this chapter.
See the PowerShell documentation for more ins and outs of variables and
object references.
570 | Chapter 9: Scripting and Automation
PowerShell Scripts
Like the WSH scripts or DOS batch files, a PowerShell script is just a text file
with a list of commands.


Pages:
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6