Automating the world one-liner at a time…
Monad provides strong support for existing apps and technology. If you use native cmdline exes, vbscripts, batch files, perl scripts etc to manage and maintain windows, you can pretty much use them the same way from monad as you would from cmd.exe.
For example, I am used to findstr.exe and xcopy.exe. I can use them from monad as is.
MSH C:\> findstr Monad monad.txt
MSH C:\> xcopy monad.txt monad2.txt
Does monad2.txt specify a file name
or directory name on the target
(F = file, D = directory)? f
1 File(s) copied
You can also use get-command cmdlet to discover them if they are in your PATH.
MSH C:\> get-command findstr
CommandType Name Definition
----------- ---- ----------
Application findstr.exe C:\WINDOWS\system32\findstr.exe
Let’s look at a vbscript example. Script Center website has a good collection of useful vbscripts. Today we will play with this one. The script uses WMI to query the machine for computer system and processor information. You can run it in Monad as follows
MSH C:\> cscript processor.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Computer Name: ABHISHEK1
System Type: X86-based PC
Number Of Processors: 2
Name: Intel(R) Pentium(R) 4 CPU 3.00GHz
Description: x86 Family 15 Model 2 Stepping 9
Processor ID: BFEBFBFF00000F29
Address Width: 32
Data Width: 32
Maximum Clock Speed: 2992
If you look at the vbscript example above, it is using WMI to query for some system properties. WMI is a useful existing management technology and Monad provides strong support for it. The primary interface to WMI in Monad is the get-wmiobject cmdlet. Let’s use it to get the same information we got from the vbscript.
First we query for an instance of the win32_ComputerSystem class
MSH C:\> get-wmiobject win32_computersystem | format-list SystemType,Name,NumberOfProcessors
SystemType : X86-based PC
Name : ABHISHEK1
NumberOfProcessors : 2
How did the get-wmiobject cmdlet discover the namespace? The default namespace used by the cmdlet is root\cimv2. But you can supply the namespace via the –Namespace parameter. The cmdlet also supports accessing information via WMI from remote machines and can also be used to browse the namespace for class information. But more on this cmdlet later; let’s complete the task at hand. We need to query WMI for instances of win32_processor class.
MSH C:\> $processor = get-wmiobject win32_processor
MSH C:\> $processor | format-list Name,ProcessorID,MaxClockSpeed,AddressWidth,Description
Name : Intel(R) Pentium(R) 4 CPU 3.00GHz
ProcessorID : BFEBFBFF00000F29
MaxClockSpeed : 2992
AddressWidth : 32
Description : x86 Family 15 Model 2 Stepping 9
Using get-wmiobject and about 3 lines of monad script we have ported the above vbscript to monad! Monad will also provide support for COM interop. You will be able to use Monad scripts for COM automation.
That’s all I have time for today. Hope you find it useful!
[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]