Chapter 15

Working with Windows PowerShell

Microsoft Exam Objective Covered in This Chapter:

  • Maintaining a SharePoint Environment

In the other chapters of this book, you focused on performing a variety of tasks using multiple tools, including Windows PowerShell. This chapter will focus on PowerShell as a tool in general and how it is used in the SharePoint Server 2010 Management Shell.

Windows PowerShell Essentials

A shell, in the world of computing, is an interface between computer users and the operating system that gives users access to the system kernel. Although the graphical user interface (GUI) can be considered a shell, the term more commonly refers to the command-line shell, which serves the purpose of launching other specific programs, browsing the directory structure of the computer, and acting as an environment for scripting.

Windows PowerShell is designed to be a command-line interface specifically for administrators. It differs from previous Windows shell environments in that it does not act as a text-processing tool but rather as a utility that processes objects based on the .NET Framework. It also comes equipped with a large number of built-in commands, called cmdlets, and presents a consistent interface across different tools and activities. Although Windows PowerShell may seem new to you, it was initially released in 2006 and is available on Windows systems including Windows XP, Windows Server 2003, and all other, more recent Windows systems. PowerShell supersedes the Stsadm.exe administration tool and supports a scripting language that is optimized to, among other things, develop command-line scripts in SharePoint Foundation 2010.

Any shell environment can seem intimidating when you don’t know your way around. As you likely experienced in some of the other chapters of this book, knowing which cmdlet to use to accomplish a specific task, knowing the command-line syntax, and knowing the various switches or parameters available can appear overwhelming. Familiarity and frequent use helps overcome those barriers. You may be a command-line guru, in which case you probably have already delved deep into the arcane secrets of PowerShell. If not, you can still become competent and even expert in PowerShell by using it as much as possible. Start by learning the basics.

Windows PowerShell First Steps

Windows PowerShell has a lot in common with other shell environments, so if you understand shell basics, you can probably make your way around PowerShell as well. However, if your shell skills are a little rusty, or even thoroughly oxidized, you can start learning here.

You don’t have to be on Windows Server 2008 to work with PowerShell. If you have Windows XP, click Start, type powershell in the Run field, and press Enter. For Vista and Windows 7, click the Windows button and do the same thing. Windows PowerShell will open on your desktop computer, as shown in Figure 15-1.

Figure 15-1: Window PowerShell 2.0

f1501.tif

How you get PowerShell depends on which OS you are running:

  • Windows XP and Windows Server 2003: PowerShell v1 and v2 versions are downloaded and installed (effectively as an OS patch).
  • Windows Server 2008: PowerShell v1 is a “feature” and can be added. PowerShell v2 versions are downloaded and installed (effectively as an OS patch).
  • Windows 7/Windows Server 2008 R2: PowerShell v2 is installed by default.
note.eps

For the latest information on PowerShell 2.0, visit the PowerShell Team Blog (http://powershell.com/cs/blogs/windows-powershell-team/default.aspx). You can find more about how to get Windows PowerShell 2.0 for pre–Windows 7 computers here: http://powershell.com/cs/blogs/windows-powershell-team/archive/2010/06/22/windows-powershell-2-0-on-windows-update.aspx.

Some of the same common actions you’re used to in other shell environments work the same way in PowerShell.

To close the shell, type exit at the prompt and press Enter.

To interrupt an action while it’s occurring in the shell, press Ctrl+C.

Getting Help

To get basic help for commands in the shell, type help command at the prompt and press Enter. The help menu will appear, as you can see in Figure 15-2.

Figure 15-2: Help menu in Windows PowerShell

f1502.tif

You can use wildcards (*) with the help command such as help get-* or help set-* if you don’t know the specific get or set command you are trying to find. If you know the letter the cmdlet starts with, you can type help get-I and receive information about all the get cmdlets starting with that letter. Another example of how to get help is typing about_* at the prompt and pressing Enter. This will result in all the general help topics prefixed with about being displayed. If a long list results, use the spacebar to scroll down the list.

Keyboard Interaction

You can use a standard set of keyboard keystrokes to elicit specific results. Feel free to try any of these in PowerShell to see how they work:

  • Backspace: Use this key to delete one or more characters behind the cursor.
  • Ctrl+left arrow and Ctrl+right arrow: Press these keys to move left or right in the current line one word at a time.
  • Delete: Use this key to delete the character directly under the cursor.
  • End: Press this key to move the cursor to the end of the current command line.
  • F7: To see the command history, press F7. A separate window will appear with the command history. To close the window, press Esc.
  • Home: Press this key to move the cursor to the beginning of the current command line.
  • Insert: Press this key to toggle between insert and overwrite modes.
  • Left and right arrows: Press these keys to move left or write in the current line one character at a time.
  • Tab: Press this key for command-line completion. It’ll save you a lot of typing.
  • Up arrow: Use this key to scroll back in the command history.

Commands

Four main types of commands are available in Windows PowerShell:

  • Applications: These are Windows programs existing on the Windows system, such as executables, PowerShell scripts, or scripts written in other languages.
  • Cmdlets: These are the PowerShell built-in commands written in a .NET language such as C# or Visual Basic that can be extended by loading PowerShell snap-ins.
  • Functions: These are commands written specifically in the PowerShell language and are dynamically defined.
  • Scripts: These are text files with a .ps1 extension that contain PowerShell commands.

You will not likely be tested on writing PowerShell scripts for SharePoint in the certification exam, so this chapter will not go into any detail about the PowerShell language. You will be working mainly with PowerShell cmdlets.

PowerShell Cmdlets

As previously mentioned, rather than accepting text input and returning text output as previous Windows command-line utilities have, PowerShell accepts and returns .NET Framework objects, allowing for improved control as well as the ability to use completely new tools and methods, such as cmdlets (pronounced “command-lets”).

At its simplest level, a cmdlet is a verb-noun pair separated by a hyphen (-) to define an action. In English, examples of this would be Find-Fred and Bring-Donuts. You’ve already experienced examples of using cmdlets in SharePoint tasks such as Get-SPWebCollection or Set-SPMobileMessagingAccount. When you issue a command such as Get-SPWebCollection, the specified object, SPWebCollection, is retrieved. When you issue a command using the Set cmdlet such as Set-Llocation, followed by a path, you will change your present working directory (PWD) to that location. The Set command is used to set session variables or parameters.

note.eps

To see a list of classes in the Microsoft.SharePoint namespace, visit http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.

Any parameters used with a cmdlet are passed as name-value pairs. Remember that cmdlets return objects in their output, and object properties display as name-value pairs, which can then be passed or piped to another cmdlet. This gives you the ability to chain cmdlets together. It’s not hard from here to see how PowerShell not only serves as a command-line tool but as a new scripting language as well.

The cmdlets you use in SharePoint are based on a specific cmdlet class: SPCmdlet. This is opposed to cmdlets for Windows PowerShell, which are from the PSCmdlet class. The verbs you use in cmdlets are Get, Set, New, and Remove. In the previous chapters, you used Get and Set almost exclusively.

Although SharePoint has its own specific namespace defining the cmdlets that can be used, you can practice with some general cmdlets that will work in any namespace. Exercise 15-1 will give you some practice. You can perform this task on any Windows computer that has PowerShell installed.

Exercise 15-1: Using Generic Cmdlets and Commands

1. On any compatible Windows system, open the Run field, type powershell in the field, and press Enter.

2. When the Windows PowerShell window opens, type Get-Acl at the prompt and press Enter to see the access control list for the local computer.

3. Type Get-Location at the prompt and then press Enter to see the present working directory (pwd).

4. Type help Get-I to see a list of all the Get cmdlets beginning with the letter I.

5. Press the up arrow to toggle through the commands you previously ran until you find a command you want to run again; then press Enter to execute the command.

6. Press F7 to view a list of the commands you have run in a separate window, use the up and down arrows to toggle through the commands; then, with the desired command highlighted, press Enter to run the command.

7. Type exit and then press Enter to close PowerShell.

While the main cmdlets are Get, Set, New, and Remove, other available cmdlets begin with Copy, Rename, and Clear. Mkdir is also available. So, using an example from the previous exercise, not only can you use Get-Location, but you can use Set-Location in order to change the current working directory. Not only can you set the contents of a file using a cmdlet such as Set-Item, but you can also use Copy-Item to copy a file, use Remove-Item to remove a file or directory, use Clear-Item to clear the contents of a file, and use New-Item to create a new empty file or directory.

Windows PowerShell for SharePoint 2010

As mentioned previously, there is a separate namespace for SharePoint relative to Windows PowerShell. You’ve probably noticed that, when you’ve executed a cmdlet specific to SharePoint, the part of the cmdlet after Get or Set begins with SP, which of course means SharePoint.

On a desktop Windows computer, you’ve already invoked the Windows PowerShell console by using the Run field. On a Windows Server machine running SharePoint, you typically don’t actually open this console but, rather, open the SharePoint Management Shell instead. To open the Management Shell, go to Start All Programs Microsoft SharePoint Products, and then click SharePoint 2010 Management Shell.

The Management Shell isn’t identical to the PowerShell console, but in the Management Shell, you can use PowerShell cmdlets to manage all the different aspects of SharePoint 2010 including creating service applications and proxies, site collections, web applications, and user accounts. Because you’re using the SharePoint Management Shell, it isn’t necessary for you to register the snap-in containing SharePoint-specific cmdlets. The registration automatically occurred when SharePoint was installed. If you try to use the Windows PowerShell console instead of the Management Shell, you’ll have to manually register the snap-in before you can utilize SharePoint specific cmdlets.

To gain access with the SharePoint Management Shell and Windows PowerShell cmdlets, you must be a member of the SharePoint_Shell_Access role or the WSS_Admin_WPG local group. When you installed and configured SharePoint, you did so with an account that contains these roles. To add someone to these roles, use the Add-SPShellAdmin cmdlet.

note.eps

For specific information about the Add-SPShellAdmin cmdlet, go to http://technet.microsoft.com/en-us/library/ff607596.aspx.

Opening the SharePoint 2010 Management Shell

When you open the SharePoint 2010 Management Shell for the first time, you may encounter the following error: “The local farm is not accessible. Cmdlets with FeatureDependencyID are not registered,” as shown in Figure 15-3.

Figure 15-3: SharePoint 2010 Management Shell error

f1503.tif

If you encounter this error, it means you are logged in as a user who does not have access to the SharePoint_Configuration database. You must belong to the SharePoint_Shell_Access role or the DB_owner role in order to have this access.

If you log in as the SharePoint administrator and then open the management console, you will have rights to the SharePoint_Configuration database, and the shell will appear as in Figure 15-4.

Figure 15-4: SharePoint 2010 Management Shell

f1504.tif

Windows PowerShell Cmdlets

As you’ve seen in the other chapters of this book, the number of different cmdlets that apply specifically to SharePoint seems vast. Just how are you supposed to know which cmdlets to use for specific situations? Even if you know the names of the SharePoint cmdlets that are available, how are you supposed to use them?

You saw previously in this chapter how to get general help in PowerShell. In the SharePoint Management Shell, you can use the help system to get information about SharePoint cmdlets. If you know nothing at all about which cmdlets are available, type get-help get-* at the command shell prompt and then press Enter. A list of all the SharePoint cmdlets and their descriptions will appear, as shown in Figure 15-5.

Figure 15-5: SharePoint cmdlet list in the SharePoint 2010 Management Shell

f1505.tif

Of course, this list scrolls by very quickly, but you can type get-help get-* | more and then press Enter. Piping the help command through more lets you go through the list one page at a time. Just press the spacebar when you want to view the next page and keep paging through until you find what you want or reach the end of the list. Press the Q key to quit the list and return to the prompt.

Once you find the name of the desired SharePoint cmdlet, you can get help information just for that cmdlet by typing get-help Get-<cmdlet name> and then pressing Enter. Since the details can be lengthy, you should pipe the help request through more.

In Exercise 15-2, you’ll see how to find the list of all the available SharePoint cmdlets, select a specific cmdlet, and then look up help for that cmdlet. You must be logged into SharePoint as an administrator to successfully complete this task.

Exercise 15-2: Getting Help for SharePoint Cmdlets

1. On a computer with SharePoint 2010 Server installed, click Start All Programs Microsoft SharePoint 2010 Products Microsoft SharePoint 2010 Management Shell.

2. At the prompt, type get-help get-* | more and then press Enter.

3. When the list of cmdlets appears, press the spacebar repeatedly until you locate the name of the desired cmdlet; then make a note of the cmdlet name.

4. Press Q to quit the help list.

5. At the prompt, type get-help Get-<name of SP cmdlet> such as get-helpGet-SPSearchService | more and then press Enter to see help for the cmdlet,as shown here.

g1501.tif

6. Read the help information and press the spacebar to page through all the information.

7. At the prompt, type get-help Get-<cmdlet name> -examples and then press Enter, such as get-help Get-SPSearchService -examples to see a list of examples for how the cmdlet is used.

8. Repeat the previous step but substitute the parameter -detailed for -examples and then press Enter.

9. Repeat the previous step but substitute the parameter -full for -detailed and then press Enter.

10. Repeat the process to get a list of SharePoint-related cmdlets and use the help steps presented in this exercise to discover more information about those cmdlets.

11. When you are done, type exit at the prompt and then press Enter to close theManagement Shell.

You can use the same process to get help for the Set, New, and Remove cmdlets. Typing help at the prompt and then pressing Enter will show you all the different methods of help available in the Management Shell. Many of these help methods, and their results may not be specifically relevant to administrating SharePoint but may eventually help you gain more skills in Windows PowerShell as your skill sets continue to develop.

Between the general syntax information yielded by the get-help Get-SP<cmdlet name> command and using the -examples parameter, you should learn enough information about a SharePoint related cmdlet to be able to execute it in your environment.

Often, you will be logged in to SharePoint as an “ordinary user,” and in it is a good security practice to only log into SharePoint as an administrator when you need to perform an administrative task. If you are logged in to SharePoint as a user and need to run a quick cmdlet in the Management Shell as an administrator, click Start, click the arrow to the right of SharePoint 2010 Management Shell, and then click Run As Administrator to open the shell with administrative rights. This is shown in Figure 15-6.

Figure 15-6: Opening SharePoint 2010 Management Shell as an administrator

f1506.tif

You can use this method to run help for PowerShell and to import modules if necessary. You can also click Start All Programs SharePoint 2010 Products and then right-click Microsoft SharePoint 2010 Management Shell and select Run As Administrator to achieve the same result.

Summary

In this chapter, you discovered the basics of using Windows PowerShell:

  • Learning PowerShell basics
  • Understanding PowerShell cmdlets
  • Learning how to use cmdlets in the SharePoint 2010 Management Shell

Exam Essentials

Understanding Windows PowerShell Basics Understand how to use common shellcommands and syntax in Windows PowerShell, including how to get help.

Demonstrating Knowledge of SharePoint 2010 Management Shell Know how to use the SharePoint Management Shell to use Windows PowerShell cmdlets that are specific tothe SharePoint environment, including how to find information about specific cmdlets.

Review Questions

1. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You understand the basic concept of a shell but are trying to understand what makes PowerShell different from Stsadm.exe. Of the following, what is true about PowerShell?

A. PowerShell is a text-processing tool.

B. PowerShell processes objects based on the .NET Framework.

C. PowerShell processes objects written in Perl.

D. PowerShell is the next generation of Stsadm.exe.

2. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are trying to understand cmdlets as a basic PowerShell concept. Of the following, what is true about cmdlets? (Choose all that apply.)

A. Cmdlets are PowerShell built-in commands written in C#.

B. Cmdlets are PowerShell built-in commands written in Visual Basic.

C. Cmdlets are PowerShell built-in commands written in Perl.

D. Cmdlets are PowerShell built-in commands that can be extended using snap-ins.

3. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are trying to learn more about cmdlets through the PowerShell help system and open Windows PowerShell on your desktop computer. Of the following, which command will give you help specific toGet-Command?

A. help

B. help command

C. help cmdlet

D. help powershell

4. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. Although you are just learning about PowerShell, it has been around for awhile in Windows systems. Of the following, on which Windows desktops would you expect to find Windows PowerShell? (Choose all that apply).

A. Windows 2000 Professional

B. Windows XP

C. Windows Vista

D. Windows 7

5. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are at a Windows PowerShell window and want to find a list of all the Get cmdlets beginning with the letter J. At the prompt, what should you type?

A. get-j

B. help get-j

C. help command get-j

D. help get command j

6. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You want to see a list of the previous commands you issued in Windows PowerShell in a separate window. What should you do?

A. Press the up arrow to toggle through the prior commands.

B. Press the down arrow to toggle through prior commands.

C. Press F7 and then toggle through prior commands.

D. Press F1 and then toggle through prior commands.

7. In Windows PowerShell, you have invoked a help command, and at the bottom of the information that was returned you see the word more. How can you see the additional information?

A. Press F1 to see the following page.

B. Press Tab to see the following page.

C. Press Q to see the following page.

D. Press the spacebar to see the following page.

8. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You have beenpracticing typing commands at the prompt and have heard that you can speed up the process of writing commands by using command-line completion. This will let you type only part of the command and then use this method to complete the line. Of the following, which method accomplishes this task?

A. Press F1 to use line completion.

B. Press Tab to use line completion.

C. Press Q to use line completion.

D. Press the spacebar to use line completion.

9. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. As part of your education, you have found out that there are three other main types of commands in PowerShell besides cmdlet. Of the following, what are those commands? (Choose three.)

A. Applications

B. Functions

C. Scripts

D. Variables

10. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are trying to learn cmdlet basics. At its most fundamental level, how is a cmdlet structured?

A. A cmdlet is a verb-noun pair such as Get-Fred or Set-Item.

B. A cmdlet is a noun-verb pair such as Fred-Get or Item-Set.

C. A cmdlet is a verb/noun pair such as Get/Fred or Set/Item.

D. A cmdlet is a noun/verb pair such as Fred/Get or Item/Set.

11. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You have been working extensively in Windows PowerShell on your desktop, navigating through various directories, and you aren’t sure where you currently are in the directory structure. How do you find out?

A. At the prompt, type path.

B. At the prompt, type directory.

C. At the prompt, type Get-Directory.

D. At the prompt, type Get-Location.

12. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are at the Windows PowerShell command prompt and want to change your current working directory to C:Users. What command must you issue?

A. Set-Location:Users

B. Set-Location:C:Users

C. Set-Location C:Users

D. Set-Location Users

13. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are at a computer with SharePoint 2010 Server installed, and you want to open the SharePoint 2010 Management Shell and practice using Windows PowerShell cmdlets. When the Management Shell opens, you receive an error that states, “The local farm is not accessible. Cmdlets with FeatureDependencyID are not registered.” What has happened?

A. You need to register the SharePoint snap-ins for the Management Shell before you can use Windows PowerShell cmdlets specific to SharePoint.

B. You are logged into the computer without sufficient privileges.

C. You cannot use Windows PowerShell cmdlets in the SharePoint Management Shell.

D. The SQL Server database server containing the database for the local farm is offline.

14. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. To expect the Management Shell to open without errors, you must log in as the SharePoint administrator or as what other roles? (Choose all that apply.)

A. You must log in as a user who is a member of the DB_owner role.

B. You must log in as a user who is a member of the SharePoint_Shell_Access role.

C. You must log in as a user who is a member of the SharePoint_Central_Administration role.

D. You must log in as a user who is the administrator for the local computer on which SharePoint 2010 Server is installed.

15. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You have opened the SharePoint 2010 Management Shell and want to find a list of Windows PowerShell cmdlets that are specific to SharePoint. Of the following, what command will accomplish this?

A. help-get get-commands

B. get-help get-commands

C. help-get get-*

D. get-help get-*

16. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. In the SharePoint 2010 Management Shell, you want to get an example of how to use the command Get-SPTimerJob. Of the following options, which will accomplish your goal?

A. get-help Get-SPTimerJob -example

B. get-help Get-SPTimerJob -examples

C. get-help Get-SPTimerJob -sample

D. get-help Get-SPTimerJob -samples

17. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are in the SharePoint 2010 Management Shell, and you want to learn the correct syntax and all possible parameters for the command Get-TimerJob. Of the following options, which will accomplish your goal?

A. get-help Get-SPTimerJob

B. get-help Get-SPTimerJob -examples

C. get-help Get-SPTimerJob -syntax

D. get-help Get-SPtimerJob -variables

18. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You have been using the help system in the SharePoint Management Shell to get information about the Get cmdlet, which is one of the common cmdlets used both in PowerShell and in SharePoint. Of the following, what other help commands return information about common PowerShell cmdlets used in SharePoint? (Choose all that apply.)

A. get-help set-*

B. get-help new-*

C. get-help remove-*

D. get-help send-*

19. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are logged into SharePoint as an “ordinary user” and want to execute a quick cmdlet in the SharePoint Management Shell as an administrator. How can you do this?

A. Open the Management Shell, click in the upper-left corner of the shell window, and then click Run As Administrator.

B. Click Start All Programs Microsoft SharePoint 2010 Products, and then clickRun SharePoint 2010 Management Shell As Administrator.

C. Click Start All Programs SharePoint 2010 Products, and then MicrosoftSharePoint 2010 Management Shell.

D. Click Start All Programs SharePoint 2010 Products, right-click MicrosoftSharePoint 2010 Management Shell, and then click Run as Administrator.

20. You are on the staff of a SharePoint administrator for your company, and you are learning Windows PowerShell basics as applied to the SharePoint environment. You are using the help system in the SharePoint Management Shell to learn more about cmdlets using to manage SharePoint. Some of the lists that output are very long, and you want to go through them a page at a time. What should you pipe the command through to accomplish this?

A. Pipe the command through more.

B. Pipe the command through less.

C. Pipe the command through page.

D. Pipe the command through toggle.

Answers to Review Questions

1. B. While Stsadm.exe processes text, Windows PowerShell processes objects based on the .NET Framework and is not the “next generation” of Stsadm.exe.

2. A, B, D. Cmdlets are PowerShell built-in commands written in a .NET language such asC# or Visual Basic (but not Perl) and that can be extended by snap-ins.

3. B. Although the other options will yield help information, using the help command will provide specific help about Get-Command, Invoke-Command, and Measure-Command in the cmdlet category.

4. B, C, D. Windows PowerShell made its advent in 2006, and the earliest Windows desktop environment on which it is available is Windows XP.

5. B. You will receive an error message if you use any help command other than help get-j to try to accomplish your goal.

6. C. You can press the up arrow to toggle through prior commands, but this will not occur in a separate window. If you have toggled through prior commands, pressing the down arrow repeatedly will let you toggle through commands subsequent to the one you are currently viewing. Pressing F1 under certain conditions will return the command you previously typed one character at a time.

7. D. Pressing the spacebar will take you to the following page, and you can review subsequent information one page at a time using this method. Pressing Q will quit the view of the help information. The other options produce no result.

8. B. Pressing F1 will yield no results. Pressing Q will add the letter Q to the line you are typing, and pressing the spacebar will add a space to the line you are typing. Pressing Tab will complete the line you are typing.

9. A, B, C. Valid PowerShell commands are applications, such as executables; functions, which are commands written in the PowerShell language; and scripts, which are text files with a .ps1 extension containing PowerShell commands. Although variables can be part of a function or a script, they are not commands.

10. A. A cmdlet is a verb-noun pair separated by a hyphen. In English, it might be expressed as Get-Fred or Bring-Donuts.

11. D. You can also type pwd or location, which will also return the current working directory or your location in the directory system.

12. C. Options A and B will produce an error, and option D will only return the prompt without changing your working directory.

13. B. If you encounter this error, it means you are logged in as a user who does not have access to the SharePoint_Configuration database. You must belong to the SharePoint_Shell_Access role or the DB_owner role in order to have this access. Log in as the SharePoint administrator and then open the management console; you will have rights to the SharePoint_Configuration database, and the shell will appear without the error message.

14. A, B. A member of either the DB_owner role or the SharePoint_Shell_Access role has access to the SharePoint_Configuration database, which is necessary in order to open the Management Shell without errors.

15. D. help-get is an improper method of getting help. You need to issue get-help.Typing get-help commands will cause an error because commands is not a valid command option.

16. B. Typing -examples after the help command will return at least one example of how to use this command in a production environment.

17. A. When you execute get-help Get-SPTimerJob, the Syntax section of the results will show all the possible variables and correct syntax for the command. Although adding the -examples variable to the help command will yield a practical example of the cmdlet, there is no guarantee that the example will include all or even any of the variables.

18. A, B, C. Although all these commands will yield valid results, the send command is not a common cmdlet used in the SharePoint Management Shell, and that help command will only yield information about a single cmdlet rather than a list.

19. D. The first two options are bogus. If you open the Management Shell using the third option, you will only be able to use it with the rights of the user account you used to login to SharePoint, and this method may cause an error.

20. A. Issue the command such as get-help get-* | more to be able to view long lists a page at a time. Although piping through less works in other shells, such as the BASH shell on Linux, it isn’t available in the SharePoint Management Shell. The other options are bogus.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset