Featured Post

SSRS 2008 R2 in CRM

The webcast recording is up for my presentation to the XRM Virtual User’s Group on SSRS 2008 R2 in CRM. In it I go over some of the new features as well as some gotchas for people looking to upgrade to the newer version.  http://www.xrmvirtual.com/events/ssrs_crm Thanks to Julie Yack et all for putting everything together!   Cheers, AJ                          

Read More

Powershell Tip: Read a Text File

Posted by Arie | Posted in Development | Posted on 03-12-2008

Tags: , , , , ,

0

So building upon our last example, we would like to of course run this function for a certain list of servers. We could just hard code another script to use in order to write out all those servers….but that would be labor intensive and we want to simplify! So the easier answer would be to just keep a list of servers in a text file. Easy to update…Easy to maintain. Then we would consume this list in our script and call our little backup function recursively.

So here we go….First, you would create a simple list of server in a text file. Place that file in your scripts directory. It should contain one server entry per line. Now let’s put together our script…

# Sample Script to do monitoring

. ./SQLScripts_Lib.ps1

#Read in a list of servers

foreach ($srv in Get-Content “C:\SQLScripts\ServerList.txt”)

{

GetBackupInfo($srv)

}

 

That’s it. Completely too simple. The Get-Content call reads in the contents of the file that it is given(full path please). We stick this in a variable and pass it off to our function. Now all we have to do if we add a server is update a simple text file.

Hope this helps some people out!

Cheers!
AJ

Write a comment