Will Script for Food, Soda or FUN!

Recently I posted a sign outside my cube and it reads:

WILL SCRIPT FOR: FOOD, SODA or FUN

(payment in advance is not required but certainly appreciated.)

Well today I had my first customer.  My team member needed to check if the users installing software at our branch locations were installing some software incorrectly.  He was concerned that they were installing an application in the root of the APPS$ share rather than the appropriate subfolder.  The test I came up with was to use the Test-Path cmdlet to see if the application exe file existed in the root of the Apps$ folder.  I could have done this as a one liner but there was a bit of added difficutly.

The first subfolder in the path was a substring of the server name.  In addition for added bling, I could have done this via P$remoting for added speed, however I have recently found a BUG where Windows 2008 non R2 servers have remoting broken for some reason in our environment.  Still attempting to fix that.

Anywho here is the script:

$Servers = Get-Content C:\scripts\BranchServers.txt
foreach($server in $Servers)
{
      $subfolder = $Server.substring(0,$Server.length - 1)
      $Result = Test-path "`\`\$Server`\$subfolder`_Apps`$`\Hys`.exe"
      if($Result){$Server}
}

And now with remoting enabled:

Invoke-Command -ComputerName (Get-Content C:\scripts\BranchServers.ps1) -ScriptBlock
{
       $subfolder = $_.substring(0,$S_.length - 1)
       $Result = Test-path "`\`\$_`\$subfolder`_Apps`$`\Hys`.exe"
        if($Result){$_}
}

Have fun scripting 😮

–ScriptWarrior

Advertisements

2 thoughts on “Will Script for Food, Soda or FUN!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s