Powershell

One of great features of Powershell is it’s raw power. 

However it DOES have limitations.  With great power comes great processing.  I caught a posting in a discussion group about finding the size of folder structure.  And you can do it in Powershell but the user needed to do it on 100’s of servers and systems.  And Powershell CAN do it but, being over the LAN, it’s slow.

But who says you ONLY use Powershell to do the tasks?  Sometimes there are established methods that already JUST WORK!  And you can you them and have the file manipulation features of Powershell do the muscle work.

What I figured out (and It seems to work very fast) is using a Good old fashioned “DIR /S > INFO.TXT” command.

Yes “DOS” or “CMD.EXE”.  “Old School” 

the reason I was thinking of this was on an Enterprise scale you’re not going to “just get permission” to throw Powershell onto 100’s of servers.  But he needs the information easily and FAST.

Well CMD.EXE is stock.  And Powershell can CERTAINLY manipulate a simple text file with a GET-CONTENT.   And the location of the Directory size is always constant.

 

So here you have it… Just an idea…  What do you think?

—————————————

Here’s the example.  You’d have to incorporate this into your Server FOREACH but here’s the idea.

Each server nightly or weekly run the following task.

DIR "C:Documents And Settings" /s > C:FOLDERINFO.TXT

Then you want to copy the file locally somehow, that will speed up the processing of the INFO.TXT file.  the 2nd last line has the size of the folder structure from this outputted text file.

copy \SERVERC$FOLDER.INFO.TXT C:LOCALFOLDER or whatever fits your environment, the trick is to have the data LOCAL to work with not over the lan

—————————————

Then pull that TEXT file into a Variable in Powershell

$DATA=GET-CONTENT C:LOCALFOLDERINFO.TXT

And the following three lines figure out the size of the Text file, Counts back two lines and figures out where the number starts (constant) and ends (Variable)

# Total lines in Text file

$TotalLines=$DATA.Count

# How big the text field is

$Outputsize=$Data[($TotalLines-2).Length

# the spot that contains the text data representing the total dir size

$DirSize=$Data[($TotalLines-2).substring(25, ($Outputsize-31))

——————————–

$Dirsize is at least now a variable with the needed data.  Most of the processing (producing the folder structure) happens on the back end servers.   User just needs a way to pull those files into the local system temporarily to pull the last line out.  It could now be printed easily.

 

See?

 

Sometimes it shouldn’t be done in just Powershell, no matter HOW much I love it

Sean
The Energized Tech