PowerShell logo The Windows PowerShell syntax was deliberately chosen to facilitate ease of use and ease of learning.  Corporate enterprise Windows administrators are the target audience.

– Windows PowerShell Scripting Guide by Ed Wilson, Microsoft Press.

I’m teaching myself PowerShell at the moment, because:

  1. it’s the future of Windows scripting.
  2. I had 1400+ computers I needed to check for a particular file, and it looked easier with PowerShell.

Future of Windows scripting.

Back in the dark ol’ days, if you needed a script created on DOS and Windows, your choices were DOS Batch, and DOS Batch.  This changed in 1991 with KiXtart.  KiXtart was created by a Microsoft employee, to provide corporate IT types with more robust logon scripting.

Like the 9 headed Hydra, KiXtart blossomed.  And got into places where it shouldn’t have gone.  I know of one 4000+ desktop company using it for software deployments.  Erkkkk!  Imagine how much spaghetti code there would have been in that.

Then VBscript.  VBscript was trumpeted by Microsoft in 1998 as the better/new way forward.  One Windows IT Pro writer said in 2001:

VBScript, one of the most powerful and underused features in the Windows environment, provides the same powerful programming tools (e.g., variable support, structured program control, the ability to leverage COM objects) that you’ll find in full-featured development languages.

It was that very powerfulness which caused some security problems with VBscript (mis)use.  So Microsoft threw the baby out with the bath water and created PowerShell to address those security issues.  Sure there are some other advantages to PowerShell, such as speed, and that it’s going to be how you script/interact with new Microsoft products.

Those 1400+ computers?

The script worked well.  Here is the cut down version:

$windows_PCs = (Get-Content c:\temp\pc-list.txt)
foreach ($computer in $windows_PCs)
{
$file_exist_path = "\\"+ $computer + "\c$\data\fred.txt"
$file_exist_OK = (Test-Path $file_exist_path)
if ($file_exist_OK)
{
write-host $computer has the fred file
}
else
{
write-host $computer is missing the fred file
}
#endif - PowerShell does not use EndIf statements, so I put this here as a boundary.
}
#next - PowerShell doesn't have a next statement either.

Output:
CATBERT has the fred file

Bookmark and Share