Interesting examples on PowerShell. Use Powershell to perform common network commands. Testing the computer with PowerShell

Cmdlets in Windows PowerShell  a lot so today I propose to consider a small list of the most useful and frequently used cmdlets with a brief description of what they know how. This guide will help you find the Windows PowerShell command you are interested in and it is aimed at the beginning system administrators.

Note! This guide is based on the PowerShell 5.0 cmdlets in the Windows Server operating system 2016.

Thanks to this network approach, we can offer many ready-made solutions. The most popular places to find them. Once again, remember that the script will read the password from this file, so you do not need to re-enter it. The script can be controlled with additional arguments.

Automatically create screenshots and save to disk. The easiest way to automate tasks is to record keystrokes with mouse clicks, and then play them when you need to. Using this program can be quite complicated in scripts, but this requires a thorough familiarization with the programming language used in it. Preparatory work. Right-click and select Edit this script. He immediately makes all the changes to the code. Without this function, you will have to restart the script or call the "Update this script" command in the pop-up menu whenever you make any changes to the script.

Useful Windows PowerShell cmdlets

In this section, I'll list the PowerShell cmdlets that you will be using for sure.

  • Get-Help - shows help for the cmdlet, functions and general help for Windows PowerShell. The help can be of several types: brief, detailed, complete and output of only examples;
  • Update-Help - loads and installs new help files, i.e. updating help;
  • Get-Command - the command for finding the desired command, you can search for both the verb and the noun, it is also possible to use a mask if you do not know the exact name of the verb or noun;
  • Get-Alias ​​- shows aliases, all or specific commands;
  • Get-PSDrive - shows the connected disks;
  • Get-Member - displays the properties and methods that the object has;
  • Get-WindowsFeature - displays information about the available roles and components of the server;
  • Install-WindowsFeature ( is equivalent to Add-WindowsFeature) - installs roles or components on the specified server;
  • Uninstall-WindowsFeature ( equivalent to Remove-WindowsFeature) - deletes the server roles or components;
  • Get-History - returns the list of commands entered during the current session.

Working with Variables

In PowerShell, in order to create a variable, set a value to it, or get this value, you usually use the dollar sign $ ( short and convenient), but for these purposes there are special cmdlets.

Two simple examples.

Create a new text document. With the help of a script you can even make a document instantly in the right folder. First go to Explorer in the folder where you want to find the new document. With it, you can record and play back mouse and keyboard operations.

In addition to this, you will find many useful scripts on the Internet. As a starting point for search, we recommend selecting a forum on the author's portal. Displays or removes a network drive.

  • Get-Variable - displays a list of variables and their values ​​( or one specified variable);
  • New-Variable - creates a new variable;
  • Set-Variable - sets the value of the variable. If the variable with the specified name does not exist, it will be created;
  • Clear-Variable - removes the value of the variable;
  • Remove-Variable - removes the variable and its value.

Formatting in Windows PowerShell

In Windows PowerShell, there is a set of cmdlets that are designed to format the output of the output of the cmdlet. They allow the user to display the result in the form in which it is convenient for him to view this result.

  • Format-List - output the result of the command in the format of the list of properties, where each new line has a separate property;
  • Format-Table - output the result of the command in the form of a table;
  • Format-Wide - output the result of the command as a wide table, in which only one property of each object is displayed;
  • Format-Custom - in this case, the formatting of the output is done using a custom view.

Import and Export

PowerShell allows you to import and export data in various common formats, for example, CSV or XML, and also redirect output of the result of the command to an external file or printer.

  • Export-Csv - export data to CSV format;
  • Import-Csv - imports data from a CSV file;
  • Export-Clixml - export data to XML format;
  • Import-Clixml - imports the CLIXML file and creates the corresponding objects in the Windows PowerShell shell;
  • Out-File - sends the output of the result of the cmdlet to an external file ( e.g., TXT);
  • Out-Printer - output of the output of the command to the printer;
  • Import-Module - adds modules in the current session.

Working with a network in Windows PowerShell

To administer the network in Windows PowerShell, there are cmdlets like:

  • Disable-NetAdapter - cmdlet disables the network adapter;
  • Enable-NetAdapter - this cmdlet includes the network adapter;
  • Rename-NetAdapter - renames the network adapter;
  • Restart-NetAdapter - restarts the network adapter;
  • Get-NetIPAddress - displays information about the configuration of the IP address;
  • Set-NetIPAddress - changes the configuration of the IP address;
  • New-NetIPAddress - creates and configures an IP address;
  • Remove-NetIPAddress - removes the IP address and its configuration;
  • Get-NetRoute - displays the IP routing table;
  • Set-NetRoute - changes the IP routing table;
  • New-NetRoute - creates a record in the IP routing table;
  • Remove-NetRoute - deletes one or more records ( IP Routes) from the IP routing table;
  • Get-NetIPv4Protocol - displays information about the configuration of the IPv4 protocol;
  • Get-NetIPv6Protocol - displays information about the configuration of the IPv6 protocol;
  • Get-NetIPInterface - displays information about the properties of the IP interface;
  • Get-NetTCPSetting - shows information about TCP settings and configuration;
  • Test-Connection - The cmdlet sends ICMP packets to one or more computers, i.e. « pings"Computers.

Working with elements

In Windows PowerShell, there are cmdlets that can work with elements, here you can understand the following items: files, folders, registry keys, and so on.

  • Clear-Item - clears the contents of the element, but does not delete the element itself;
  • Copy-Item - copies the item;
  • Get-Item - gets the item in the specified location;
  • Invoke-Item - executes the default action on the specified element;
  • Move-Item - moves the item;
  • New-Item - creates a new element;
  • Remove-Item - removes the specified items;
  • Rename-Item - renames an item in the Windows PowerShell provider namespace;
  • Set-Item - changes the element;
  • Get-ChildItem - returns items and child elements in one or more specific locations;
  • Get-Location - displays information about the current location.

Active Directory Cmdlets (AD)

Windows PowerShell, of course, allows you to work with the Active Directory directory service. For these purposes there are quite a few cmdlets, here are some of them:

  • New-ADUser - creating a new user in Active Directory;
  • Get-ADUser - displays information about Active Directory users;
  • Set-ADUser - changes the user Active Directory;
  • Remove-ADUser - deletes the Active Directory user;
  • New-ADGroup - cmdlet creates a group in Active Directory;
  • Get-ADGroup - displays information about a group or performs a search to get multiple groups from Active Directory;
  • Set-ADGroup - the cmdlet changes the group in Active Directory;
  • Remove-ADGroup - deleting a group in Active Directory;
  • Add-ADGroupMember - cmdlet adds user, computer, or group accounts as new members of the Active Directory group;
  • Get-ADGroupMember - displays information about the members of the Active Directory group;
  • Remove-ADGroupMember - removing items from the Active Directory group;
  • Set-ADAccountPassword - reset the password of the Active Directory account;
  • Disable-ADAccount - disables the Active Directory account.
  • Enable-ADAccount - Enables the Active Directory account;
  • Unlock-ADAccoun - unlocks the Active Directory account;
  • New-ADComputer - create a new computer account in Active Directory;
  • Get-ADComputer - displays information about one or more computers in Active Directory;
  • Set-ADComputer - change the computer account in Active Directory;
  • Remove-ADComputer - remove the computer from Active Directory.

Working with Hyper-V

To work with Hyper-V in Windows PowerShell, there are many cmdlets, here is a short list:

  • New-VM - creating a new virtual machine;
  • Set-VM - configuration of the virtual machine;
  • Start-VM - start the virtual machine;
  • Stop-VM - closing, shutting down or saving a virtual machine;
  • Import-VM - import a virtual machine from a file;
  • Move-VM - move the virtual machine to the new Hyper-V host;
  • Remove-VM - delete the virtual machine;
  • Rename-VM - rename the virtual machine;
  • New-VHD - creation of one or several new virtual hard disks;
  • Set-VHD - setting up a virtual hard disk;
  • Test-VHD - testing a virtual hard disk for problems that would make it unsuitable for use;
  • Add-VMDvdDrive - adds a DVD to the virtual machine;
  • Remove-VMDvdDrive - removes the DVD from the virtual machine;
  • Add-VMHardDiskDrive - adds a hard disk to the virtual machine;
  • Remove-VMHardDiskDrive - removes one or more virtual hard disks (VHDs) from the virtual machine;
  • Add-VMNetworkAdapter - Adds a virtual network adapter to the virtual machine;
  • Remove-VMNetworkAdapter - removes one or more virtual network adapters from the virtual machine;
  • Copy-VMFile - copy files to a virtual machine;
  • Get-VMVideo - displays information about the video settings for virtual machines;
  • Move-VMStorage - move the vault of the virtual machine.

Working with background tasks

In Windows PowerShell, you can run tasks in the background so that, without waiting for the end of the command ( for cases when the task is performed for a long time), continue to work in the current session. To work with background jobs in PowerShell, there are the following cmdlets:

  • Start-Job - start the background task;
  • Stop-Job - stop the background task
  • Get-Job - view the list of background tasks;
  • Receive-Job - view the result of the background task execution;
  • Remove-Job - delete the background task;
  • Wait-Job - to transfer the background task to the foreground, in order to wait for its end.

Working with objects

Since PowerShell works with objects, it allows you to perform certain actions on these objects, for example:

  • Measure-Object - The cmdlet allows you to calculate on the basis of object properties such numerical aggregating parameters as: minimum, maximum, average value, amount and quantity. For example, you want to know the maximum or average file size in a specific directory, or simply find out the number of files ( running processes, services, and so on);
  • Select-Object - with this cmdlet you can select certain objects or properties of these objects, for example you want to display only the file name and its size;
  • Sort-Object - sorts objects by property values;
  • Where-Object - cmdlet to set a condition for retrieving objects based on the values ​​of their properties;
  • Group-Object - group objects that contain the same value for the specified properties;
  • ForEach-Object - enumeration of objects in order to perform a certain operation on each of these objects.

PowerShell cmdlets for remote management

With Windows PowerShell, you can run commands not only on the local computer, but also on one or even several remote computers.

  • Enter-PSSession - starts an interactive session with a remote computer;
  • Exit-PSSession - ends the interactive session with the remote computer;
  • New-PSSession - creates a permanent connection to a local or remote computer;
  • Remove-PSSession - closes one or more Windows PowerShell sessions;
  • Disconnect-PSSession - disconnects from the session;
  • Connect-PSSession - connects to disconnected sessions;
  • Get-PSSession - Gets Windows PowerShell sessions on local and remote computers;
  • Invoke-Command - executes commands on local and remote computers.

Working with services and processes

PowerShell, of course, knows how to manage services and processes in Windows, for this there are such cmdlets as:

  • Get-Process - displays information about running processes on the computer;
  • Start-Process - starts one or more processes on the computer;
  • Stop-Process - stops one or more running processes;
  • Get-Service - displays information about services;
  • Restart-Service - restarts the service;
  • Start-Service - starts the service;
  • Stop-Service - stops the service;
  • Suspend-Service - suspends the service;
  • Set-Service - Using this cmdlet, you can change service properties, for example, description, display name and start mode. You can also use it to start, stop, or pause the service.

Work with computer

Windows PowerShell allows you to perform administrative tasks for the operating system and the computer as a whole, for example, restart the operating system or rename the computer.

  • Restart-Computer - the cmdlet restarts the operating system ( reboots the computer);
  • Stop-Computer - turns off the computer;
  • Rename-Computer - renames the computer;
  • Checkpoint-Computer - creates a system restore point on the local computer;
  • Restore-Computer - starts the system recovery on the local computer;
  • Disable-ComputerRestore - disables the system restore function on the specified disk of the file system;
  • Enable-ComputerRestore - enables the system restore function on the specified disk of the file system;
  • Remove-Computer - removes the local computer from the domain;
  • Get-EventLog - displays information about events in the event log, or a list of event logs on a local or remote computer;
  • Clear-EventLog - deletes entries from the specified event logs.

Working with content

To manage content, for example, text in a file in Windows PowerShell, there are special cmdlets such as:

  • Get-Content - retrieves the contents of the element ( for example, reads a file);
  • Add-Content - adds content to the specified elements, for example, text to a file;
  • Clear-Content - removes the contents of the element, but does not delete the element itself;
  • Set-Content - writes or replaces the content in an element with new content.

Other Windows PowerShell cmdlets

Also I would like to highlight the following Windows PowerShell cmdlets, which you will certainly need and will be useful.

  • Get-ExecutionPolicy - Use this cmdlet to find out the current Windows PowerShell execution policy for the current session;
  • Set-ExecutionPolicy - The cmdlet changes the Windows PowerShell execution policy;
  • Write-Host - displays the information on the screen ( writes text);
  • Read-Host - reads the input line from the console;
  • Write-Warning - displays a warning message;
  • Write-Error - the cmdlet declares an error and outputs it to the error stream;
  • Get-Date - returns the current date and time;
  • Set-Date - The cmdlet changes the system date and time on the computer.

Here we are with you and reviewed the useful and frequently used Windows PowerShell cmdlets, I hope this directory will be useful to you, good luck!

Our review focuses on using key features of Windows PowerShell to perform various administrative tasks. First, let's look at the built-in tools for getting to know the features of Windows PowerShell.

  Introduction to Windows PowerShell Features

So, you are the administrator who needs to learn Windows PowerShell in the shortest possible time. The first thing you will probably do (of course, in addition to referring to the documentation and help system), use the Help command (Figure 1).

Having carefully studied the information displayed on the screen, we come to an understanding of the following conceptual things: in Windows PowerShell there are aliases, cmdlets, providers, as well as help files. Aliases (alias) serve to simplify the input of commands (for example, clc  is an alias of a team Clear-Content), cmdlets are the implementation of all built-in commands in Windows PowerShell, providers provide access to the file system, registry, certificate store, etc., and help files are used to obtain additional information. To get a detailed description of the command, use the following syntax:

PS C:\u003e Help Get-Command

As a result of this command, we get a complete description of the command Get-Commandincluding its purpose, syntax, options, and so on. (Figure 2).


To get a list of all built-in commands, use the following syntax:

PS C:\u003e Get-Command

Note that all commands consist of a verb and an adjective (for example, Get-Content, Export-Console) and all commands support a single naming system - for example, to finish something, the Stop verb is always used, not Kill, Terminate, Halt, or other synonyms, which greatly simplifies the study of PowerShell capabilities (Figure 3).


Command Get-Service  is used to get a list of all the services running on this computer. For example,

PS C:\u003e Get-Service

returns the list shown in Fig. 4.


To get the list of processes that are currently running on the computer, the command Get-Process  (Figure 5):


PS C:\u003e Get-Process

In Windows PowerShell, automatic completion of the input is supported. To verify this, type Get-P  and press the TAB key: you will be able to select all the commands starting with the entered characters.

For information about only one process as an argument to the command Get-Process  the name of this process is given (Figure 6):

PS C:\u003e Get-Process explorer

To get a list of all processes whose names begin with a specific character, just specify this symbol and "*" (Figure 7):


PS C:\u003e Get-Process i *

Note the columns that contain information - Handles, NMP (K), etc. By default, the information is displayed as a table, but in fact all commands return objects. These objects can be passed to the input of other commands using the symbol "|" (Figure 8):


PS C:\u003e Get-Process i * | format-list

Now the list of processes is available in another view. For more information about the various formats, you can use the following command:

PS C:\u003e Help format *

Other possible formats:

PS C:\u003e Get-Process i * | format-wide

PS C:\u003e Get-Process i * | format-custom

Since the output always produces an object, you can manipulate it to perform additional operations, for example, filtering:

PS C:\u003e Get-Process | where ($ _. handlecount -gt 400)

or sorting:

PS C:\u003e Get-Process | where ($ _. handlecount -gt 400) | sort-object Handles

A quite reasonable question may arise: how did we know that an object describing a process has a property handlecount? To get a list of all object properties, use the following command (see Figure 9):


PS C:\u003e Get-Process | Get-Member

Execute the command Get-Process | Get-Member Company  - With the default formatting, it is not possible to obtain the desired data. Convert the resulting command to:

PS C:\u003e Get-Process | Get-Member Company | Format-List

The result of its transformation is shown in Fig. 10.


PS C:\u003e Get-Process | sort-object Company | format-table-Group Company name, description, handles

The result of this command is shown in Fig. eleven.


Command stop-process  allows you to stop a running process, for example:

PS C:\u003e Get-process notepad | stop-process

This feature is not always safe, so it's better to use these commands with the option whatif, which shows what happens when a particular command is executed, but in fact the command is not executed:

PS C:\u003e Get-Process notepad | stop-process -whatif

In addition, you can indicate the need for confirmation before executing the command:

PS C:\u003e Get-Process notepad | stop-process -confirm

The result of the command with confirmation is shown in Fig. 12.


In the last example, we get a description of the actions that the command executes, and we can choose whether to confirm it or not.

In addition, you can create your own batch files, which are files with the extension * .ps1, in which the PowerShell commands are placed, and execute them. For security reasons, batch files must be signed. When testing, you can disable the requirement to run only signed files:

PS C:\u003e Set-ExecutionPolicy Unrestricted

but after the test is over, do not forget to re-enable this option with the following command:

PS C:\u003e Set-ExecutionPolicy AllSigned

After getting acquainted with the basics of Windows PowerShell let's see how with this utility you can solve various administrative tasks.

  Working with the file system

One of the tasks that many IT specialists often face is manipulation of files, such as copying, moving, renaming, deleting files and directories. In Fig. Figure 13 shows the basic Windows PowerShell commands used to manipulate the file system: new-item, copy-item, move-item, rename-item  and remove-item.


Unlike other shells in which there is a set of commands for files (for example, delete or rename), and a set for directories (for example, rd or md), in Windows PowerShell a single set of commands is used to manipulate both files and catalogs.

The first command in our example - new-item TextFiles -itemtype directory  - used to create a new TextFiles subdirectory in the current directory. If you omit the parameter -Itemtype, Windows PowerShell will ask if we create a file or a directory. Note that the team new-item  there is an alias - ni. In a reduced form, our first team will look like this:

PS C:\u003e ni TextFiles -itemtype directory

Then we use the command copy-item  (aliases - cpi, cp, copy) to copy all files with the * .txt extension to the TextFiles subdirectory. If you use this command in a batch file, it makes sense to make it more understandable by specifying the parameters -Path  (source) and -Destination  (receiver):

PS C:\u003e copy-item -path '. \\ *. Txt' -destination '. \\ TextFiles'

After executing the copy command, we use the command set-location  to go to the TextFiles subdirectory. Using the command rename-item  rename the psdemo.txt file to psdemo.bak. If necessary, you can apply options -Path  and -NewName. After the file is renamed, move it to one level up using the command move-item. Then apply the command set-location, or more precisely - its alias sl  to go to another directory. Manipulations with the file system, we end by deleting the entire TextFiles directory, using the command remove-item. Because the TextFiles directory contains files, the option is applied -Recurse. If this option is not specified, Windows PowerShell will ask for confirmation before executing the command remove-item.

  Working with the registry

When performing various settings and trying to detect any parameters, we sometimes have to access the system registry in search of keys, values, etc. With the use of the capabilities of Windows PowerShell, this task can be solved in a fairly simple way. The features of Windows PowerShell are shown in Fig. 14.


Our first team uses an alias sl  to execute the command set-location, which changes our current location from the file system to the HKEY_CURRENT_USER branch in the system registry:

PS C: \\\u003e sl hkcu:

Note that, as in the case of working with the file system, PowerShell uses a special provider to access the registry.

The analogues of the above command are the commands:

PS C: \\\u003e sl registry: hkcu

PS C: \\\u003e sl hkey_current_user

The following command loads the contents of the entire HKEY_CURRENT_USER registry branch into the reg variable:

PS HKCU: \\\u003e $ reg = gci. -Rec -ea silentlycontinue

For this we use the command get-childitem  (alias - gci), the principle of which is similar to working with the file system. The first argument of this command is "." - indicates that we want to get the contents of the current registry branch - HKEY_CURRENT_USER. The second argument is a short for the option -Recurse and indicates that we need recursive data collection from all the branches of the current branch of the registry. And finally, the third argument - –Ea silentlycontinue  - indicates that the command should continue to be executed even in case of errors related to the lack of access rights to certain registry branches.

The following command in our example:

PS HKCU: \\\u003e $ s = $ reg | % (if (gp $ _. pspath) –match ‘PowerShell’) ($ _. pspath))

copies data from the registry containing the string ‘PowerShell’. We start by taking an object. reg  and redirect him to the team % which is the alias of the command for-each. It performs a recursive traversal of all registry entries in the object. reg  and at each step saves the item in a special PowerShell object named ‘_’ . In curly brackets, we specify the actions that should be performed at each step of the command for-each. Inside block for-each  we use verification if  in order to find out if the current registry entry and its pspath property match, which we get by calling the command get-itemproperty  (via alias gp), our criterion - the presence of a string ‘PowerShell’. If a match is found, we return the value of the property. pspath. All matches found are stored in the object.   s.

We end the work with the registry by redirecting the search results to the team. select object  (via alias select) and show the first two results found. As an exercise, you can redirect the final results to a file using the command out-file.

  Access to processes

Another challenge that IT professionals may encounter is related to the detection of anomalies in the operation of the system, such as processes that consume large amounts of memory. Let's see how this task is accomplished using Windows PowerShell (Fig. 15).


In the first command, we store information about all processes running on this computer in a variable $ allprocs:

PS C: \\\u003e $ allprocs = get-process

After that we redirect the received information to the team. for-each, which can also be indicated by an alias %   or foreach. This command enumerates all objects associated with the process, and at each step stores information in the internal object. $_ . This object can be called the current object. As parameters for the command for-each  we specify the comparison of the value of the property virtualmemorysize with the memory size we are interested in (20 MB in our example). If the value of this property for the current object is greater than the specified value, we display the name of the process on the screen. Note that PowerShell supports the main abbreviations for specifying sizes - KB, MB, GB, which is very useful, since you do not need to count zeros when specifying amounts of memory, disks, etc.

  Syslog access

When trying to find the causes of failures, we often refer to the system log, which stores a lot of useful information about events that occurred in the system. Usually, the Event Viewer (eventvwr.exe) utility is used to examine the system log. In PowerShell, we can use built-in commands, such as get-eventlog, to quickly examine the contents of the system log (Fig. 16).


Our first command loads the key information from the system log:

PS C: \\\u003e get-eventlog –list

Without using the option –List  PowerShell will prompt you for the exact name of the system log. In our example, we see several entry points in the system log: Application, Internet Explorer, System, Windows Power Shell, etc. Our next command retrieves syslog entries that are of type “Error”:

PS C: \\\u003e $ bad = get-eventlog “System” | where-object ($ _. EntryType –eq “Error”)

We use the team get-eventlogwhich parameter we specify “System”  to retrieve only system records, we could specify this more clearly by applying the parameter logName. Variable content $ bad  transmitted to the input of the team where-object  to filter only records of interest. As command arguments where-object  we indicate that we are only looking for records that have a property EntryType  equally “Error”.

We are completing the study of the system log by displaying the last five error records using the command select object  with parameter –Last:

PS C: \\\u003e $ bad | select object –last 5

  WMI access

As we know, Windows Management Instrumentation (WMI) is Microsoft's implementation of the Common Information Model (CMI) standard. In most cases, WMI is used by IT specialists to obtain information about the hardware and software installed on this computer. As we will see in the following example, using Windows PowerShell makes it much easier to access information stored in WMI (Fig. 17).


In the first line, we apply the command get-wmiobject for information about the file used for swapping memory to disk and storing this information in a variable $ pfu:

PS C: \\\u003e $ pfu = get-wmiobject - class ‘win32_pageFileUsage’

PS C: \\\u003e $ pfu | get-member -membertype property | where_object ($ _. name –nomatch ‘_’)

You can usually use the command to find information on a particular class. get-member  without specifying parameters, but in our example we are interested only in the available properties and only those that do not contain an underscore in the name. An attentive reader may ask: how have we learned about the existence of a class? win32_pageFileUsage? After all, it is known that WMI supports more than a thousand classes, in addition to this, a number of applications add their own classes. You can use the command:

PS C: \\\u003e get-wmiobject –list

for a list of all existing classes in the system. After we have determined the class properties available to us, we display the contents of the properties of interest to us on the screen:

PS C: \\\u003e $ pfu.caption; $ pfu.currentusage

The second part of our example is devoted to another class - win32_DiskDrivewhich stores information about the disks installed in the system. This class is an example of a WMI class containing more than one object. In our example, we define the value of the property. caption  the first disk installed in the system:

PS C: \\\u003e $ dd.caption

  Using XML Files

Recently, XML files are increasingly used to store configuration information. As the data in the XML file accumulates, it becomes less and less convenient to read. Next, we will look at how to use Windows PowerShell features to work with XML files.

For example, take the Windows Calendar configuration file, which looks like this (Fig. 18):

and perform above it the manipulations shown in fig. 19.

In the first line, we load the contents of the entire XML file into a variable using the command get-content:

PS C: \\\u003e $ doc = get-content ‘. \\ Settings.xml’

Pay attention to the application of the data type : if you do not specify the use of data of this type, just text will be loaded into the variable.

In the second line, we select a specific branch of the XML file — the method is used for this. selectnodes  an object that stores XML data and an XPath description of the branch address:

PS C: \\\u003e $ settings = $ doc.selectnode (‘CalendarSettings / X-Root / VCalendar’)

After that we use the command foreach object  to get the property value Name  for all items in a given branch.

  Conclusion

We looked at the main features of Windows PowerShell to simplify the tasks faced by IT specialists. As we know, these tasks are often solved using the VBScript scripting language. In Windows PowerShell, you can use existing code in VBScript, and therefore, the migration is greatly simplified (Figure 20).


The example above shows how you can use existing VBScript code in PowerShell. In the first line, we create a new COM object, which is the core of script program execution - ScriptControl. We then indicate that we will use the Visual Basic Script language. The third line sets the actual code in VBScript - in our example, this is a call to the MsgBox function, but in practice you can, for example, load the code of a file into a variable. And finally, in the last line, we add VBScript code to our object — and the code goes to be executed.

  Network resources

Product Team Blog: http://blogs.msdn.com/PowerShell/.

Utilities, editors and add-ons: http://www.powershell.com/.

Dmitry Sotnikov's blog from the company Quest: http://dmitrysotnikov.wordpress.com/.

PowerGadgets is an example of unlimited PowerShell extensions:

Like this article? Share with friends: