Wikipedia says the following about Windows PowerShell: “PowerShell (including Windows PowerShell and PowerShell Core) is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and CIM enabling management of remote Linux systems and network devices. Initially a Windows component only, PowerShell was made open-source and cross-platform on 18 August 2016.”
If you are new to PowerShell, like me, that’s a lot to take in at one time. I have a previous blog post introducing the Windows 10 command line. The Windows 10 Command Prompt can trace its ancestry back more than three decades. Windows PowerShell is distinctly more modern, with version 1.0 arriving on the scene a mere decade ago.
Windows PowerShell helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows. PowerShell is built on top of .NET framework which gives an edge over the other tools when it comes to integration and automation of Microsoft product and technologies.
The book called Top 10 Tools, Windows 10 IT Pro Essentials by Ed Bott discusses the PowerShell, among many other topics. You can download it free at the Microsoft website. You may need to log in to download it.
Ed Bott writes: “The command line is useful for some file management tasks, with syntax that hasn’t changed much since the days of MS-DOS. Thanks to wildcard characters, you can change the extension on a group of files in a folder, for example, using the command ren *.htm *.html. That job is nearly impossible in File Explorer.”
Poweshell offers you cmdlets instead of a limited set of commands that DOS has. The power of these are twofold: Combining them into scrips and the fact that you have access to control almost anything in Windows, including the file system, the registry, certificate stores, Microsoft Azure and Office 365. Cmdlets are available in core modules that are included with every edition of Windows 10.
This is one of the first commands you will want to use. Add a word to the end of Get-Help and you can find cmdlets that include that term. If you know there’s a cmdlet for managing BitLocker but you can’t remember exactly which one you need, try Get-Help Bitlocker to display this list.
Ed Bott in the book says: “Although Windows PowerShell cmdlets follow consistent capitalization, you don’t need to worry about case. And if you’re not sure of the exact name of a cmdlet, you can press the Tab key and use IntelliSense to offer suggestions. For example, type get-p and then press Tab to see the first matching cmdlet, Get-Package. Keep pressing Tab to cycle through Get-PackageProvider, Get-PackageSource, Get-Partition, and so on.”
Windows PowerShell Integrated Scripting Environment (ISE)
This offers a point-and-click graphical interface that takes a lot of the guesswork out of typing cmdlets. The Windows PowerShell ISE is tailor-made for creating Windows PowerShell scripts and its Commands add-on serves as a useful training tool. Just type ise at the PowerShell window. The window in the screenshot is dragged in much smaller than you would normally have it set at to just to make it more easily fit on the screen.
You may get an error similar to the following screenshot of an error message when you try to run a command from a script.
Ed Bott’s free eBook discusses other topics as well, such as Hyper-V, the File Explorer, Registry Editor, Event Viewer, Task Manager, Disk Management, Sysinternals, DaRT and Azure.
Sysinternals Suite can be downloaded here. It’s 21MB. There are many parts to it. It is probably easiest to just download the whole suite. Many of these programs have been replaced by native Windows programs. There are still many useful utilities in this however.
You can get part of a WMI instance with the following code running in Windows Powershell. This code is at the MSDN website of Microsoft. The data is simply returned to the next line in Powershell. DeviceID is not the only thing in this class. You can try FreeSpace instead of DeviceID.
(Get-WmiObject -class Win32_logicalDisk).DeviceID
In Windows, at a DOS prompt (command line – Search, cmd
using System.Management; ... ManagementObject myDisk = new ManagementObject("Win32_LogicalDisk.DeviceID='C:'"); string myProperty = myDisk.GetPropertyValue("VolumeSerialNumber").ToString(); Console.WriteLine(myProperty);