您好,欢迎光临本网站![请登录][注册会员]  
文件名称: Getting-Started-With-Microsoft-PowerShell.pdf
  所属分类: 其它
  开发工具:
  文件大小: 433kb
  下载次数: 0
  上传时间: 2019-07-03
  提 供 者: moza*****
 详细说明:This document assumes you are working on a University of Edinburgh Sup- ported Windows Desktop. The exercises may work in other environments but this has not been tested. If following this document you may need to search the Internet for additional modules and follow the instructions on how to insta11. 4 Exercis 11.5 Advanced: Handling Xml data and loading a. Net framework 28 12 Further He 30 13 Listings 32 1 About Power shell Power Shell is a registered trademark of Microsoft Corporation. Power Shell s provided by Microsoft Corporation and is a well thought out, very usable and powerful scripting language. The influence of other scripting languages not just Microsoft can be seen In Power Shell commands(often called cmdlets) have the form verb-noun that is a verb indicating the action and a noun indicating the object for example get-childitem Power Shell itself is provided as a command line environment. In addi tion to all the Power"" one may call a non-Power Shell program directly (e.g. notepad. exe) 2 Getting started This document assumes you are working on a University of Edinburgh Sup- ported Windows Desktop. The exercises may work in other environments but this has not been tested. If following this document you may need to search the internet for additional modules and follow the instructions on how to install them. Unless you know what you are doing, it is sensible to only install extra Power Shell functionality from genuine Microsoft sites Readers will find the exercises easier if they have previous experience of scripting or programming languages. Additionally, Power Shell uses pipelines extensively so prior attendance at Unix 1 and Unix 2 courses will be and advantage 1. Click on the start but 2. Type Power shell 3. You should now see Windows Power Shell(figure 1) Windows Power Shell ISE(Figure 2) 2y Wir dows Pcwershel Figure 1: Power Shell -the command line environment If running scripts, the first option of using the Power Shell directly is fine For creating and editing scripts the Power Shell ISE(Integrated Scripting Environment )is very useful You may see additional options but these are the two to use for this course 2.1 Exercise 1. Run Power Shell. Type exit and press the Enter key. What happens? 2. Run PowerShell ISE. Click on the Help menu. Click on Update Win- dows Power Shell Help. You will notice in the window below a com. mand update-help runs and then usually produces an error. This is normal on the University of Edinburgh Supported windows Desktop 3. Read the red error text. Can you determine why the comnand failed? a Windows Powershell ISE file Edit Vicw Tools Debug Add ons +clp 日40入0p日目口世 Run script (F5) Untitled.ps1 x Sday= tuesday 2 Sday PS M: \> Sday="tuesday Sday Completed I Ln 2 Cal 5 I 170% Figure 2: Power Shell TSE- An integrated script, editor 3 commands Commands may take none, one or several parameters and one, none or several values(see Listing??, page??). Users of Unix shell environments will quickly appreciate that the developers of power shell have implemented command syntax in a similar way The command write-host can be used with no parameters, in which case it will create a blank line of output(see Listing 2, page 6) We can find options for write-host by typing help write-host (see Listing 1: CoMmand Syntax - [- I [-J [-] Listing 2: Hello world PSM:、> write-host PS M:\> write-host Hello, World Hello world Command Aliases clear-host cls, clear format-list A get-childitem gci, Is, di get-content gc, cat, type get-location gl, pwd get-member 8 remove-item ri. rm. rmdir. del erase rd write-output write, echo Table 1: Some Power Shell Command Aliases Listing 3, page 7). For extra detail, add the - full"option: heLp-full write 3.1 Exercise 1. Type write-host"Hello World"and press the Enter key 2. Type write-host-foregroundcolor yellow"Hello World 3. Get Power Shell to print in blue text on a yellow background? clue use the -backgroundcolor parameter 4. Type help cLear-host-onLine What happens? 4 Aliases Many commands have aliases(see Table 1)and for those who have used DOS or Unix these can be very familiar. Aliases are short forms of a command. So for someone used to using the command pwd ty ping help pwd will indicate that the underlying command is actually get-Location. However, if coning from a Unix or DOS environment, typing the form you are familiar with makes adopting powershell easier Listing 3: Getting help for the write-host command S M:\> help write-host Write-host SYNOPSIS customized output to a hos IYNT Write-Host [[-Object J ][-Backgroundcolor ConsoleColor> [-ForegroundColor [] DESCRIPTION The write-Host cmdlet customizes output. You can specify the color of text by using the Foregroundcolor parameter, and you can specify the background color by using the BackgroundColor parameter. The Separator parameter lets you specify a string to use to separate displayed objects. The particular result depends on the program that is hosting Windows Power shell RELATED L⊥NKS Online Version http://go.microsoftcom/fwlink/?linkid=113426 Clear-host Uut- Host Write-Debug Write-Output Write-Progress Write-Verbose write-Warning REMARKS To see the examples, type: get-helpuWrite-Host uuwu-examples For more information, type:"get-help Write-Host lullmlI-detailed technical informat i get-helpuWrite-Host NuuL-full For online help, type: "get-helpuWrite-Hostu-online 5 Variables in Power Shell Variables are labels we use to store data that can vary(hence the name variable In Power Shell variables are referenced and dereferenced by appending the variable name with symbol In Power Shell variables can be of many types integers(whole numbers, positive or negative, e.g. 1,5, -17, 0 doubles(numbers with decimal places, positive or negative, e, g. 1.5 5.0,-17.2,0.45) strings(sequences of characters that make, for example, words or sen tences arrays(sequences of variables referenced by an integer index, for exam- ple strings can be treated as arrays) hash tables(sometimes called dictionary, these are key value pairs objects(an object is may contain a complex set of variable types and associations)-some examples include processes services event logs conputers XML anything you can think might need a variable 5.1 Integer variables Variables can handle numbers and perform arithmetic operations. There are several types of variable that can contain numbers. The simplest variable type is the [int] type for integers(see Listing 4, page 9) Power Shell trys to do the right thing. The variable Sa in Listing 5(page 9) s an integer. We the redeclare Sa and it becomes a string. The answer provided if we now add the two variables will depend on the type of the first variable listed Listing 4: Integer variables and arithmetic PS M:\> int] Sa PS M:\> [int] Sb=7 PS M:\>a PS M:\>a+sb 12 Listing 5: Integers and strings PS M:\> [ int] $b=7 pSM:\>$a=4 PS M:\> Sa. getType(. Name Int32 PS M:\> Sa+sb 11 PSM:\>$a="4 PS M:\>a. getType(). Name string sM:>串a+$b > 5.2 Doubles Variables of type [double] are similar to integers in that they hold numbers however the number can contain fractional parts as decimals(see Listing 6 page 9) 5. 3 String Variables To assign the value Tuesday to variable called"day we type Sday="Tuesday as see in Listing 7(page 10) We can also ask the user to enter information using the read-host com- mand(listing 8, page 10 The read-host command echoes back what was typed however if we assign that value to a variable, say Sname then we can capture the user Listing 6: Arithmetic with numbers with decimal points PS M:\> double $a=4.0 PS M:\> double $b=3.5 PSM:\>串a-$b 10
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 输入关键字,在本站1000多万海量源码库中尽情搜索: