Fries? A drink? A kids toy? As it turns out, not much. This is just one example of what has been a trend that really bothers me about the so-called “examples” of PowerShell being published on the net lately. Most are focused on WMI queries (WQL), or COM marshalling using the New-Object –COM method. This really doesn’t do anything innovative or beneficial beyond learning a “different” way to code. All of the WQL examples are simply search/replace code chunks which look almost identical to VBscript examples.
VBScript
Set objOutlook = CreateObject("Outlook.Application")
Set Namespace = objOutlook.GetNamespace("MAPI")
For each f1 in NameSpace.Folders
wscript.echo f1.Name
Next
For each objFolder in NameSpace.Folders
For each f1 in objFolder.Folders
wscript.echo vbTab & f1.Name
Next
Next
PowerShell
$Outlook = New-Object -com Outlook.Application
$Namespace = $outlook.GetNamespace("MAPI")
"{0} Root Folders: " -f $Namespace.folders.count
foreach ($Fl in $namespace.Folders) {
" {0}" -f $Fl.Name}
""
foreach ($Folder in $Namespace.Folders) {
"`'{0}`' subfolders: " -f $Folder.Name
foreach ($fl in $Folder.Folders) {
" {0}" -f $Fl.Name
}
}
I’m not at all trying to “bash” PowerShell. It’s a cool language, but it has it’s issues that bother me. I don’t consider it a classic or “true” scripting language as much as programmatic macro language. Most of the benefits it provides via brevity of code are derived from cmdlets, which are similar to making DLL’s for COM extensibility, or UDF files for KiXtart, and so on. Blah blah blah. whatever. I’m no pundit, so what I have to say doesn’t really matter that much really. I forgot what point I was trying to make.
No comments:
Post a Comment