On my quest for PowerShell knowledge I was working on a script to rescan HBA’s and then to list the paths to the datastores but, I only wanted the script to run on certain specific hosts at a time. Usually the rule is when you add storage or paths to an ESX host you would do this to all hosts in the cluster at the same time and could use PowerShell to list the members of a cluster to work with but I was exploring the option of creating a list of the ESX hosts that I wanted the script to run on and have that list saved in a file. Using the “get-content” cmdlet, I was able to do just that. The only other things was the “foreach” loop, when reading the content of a file, you need to use “foreach-object” cmdlet. Below is an example of the code to read the serverlist.txt file and then use that information to rescan and then refresh the HBA’s.
get-content -path d:\scripts\serverlist.txt | foreach-object {Get-VmHostStorage (Get-VmHost -Name $_ ) -RescanAllHba}
Start-Sleep -s 30
get-content -path d:\scripts\serverlist.txt | foreach-object {Get-VmHostStorage (Get-VmHost -Name $_ ) -Refresh}
Nothing to exciting, just another method of getting information for your script to run against.
Previous Post
vSphere Service Console Partitioning
Next Post
Important Update About vWire
This entry was posted on Tuesday, December 8th, 2009 at 8:17 am and is filed under Virtual Tech. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.







December 8th, 2009 9:05 am
[...] Virtual Black Hole » Blog Archive » Using PowerShell To Get Content From a File http://www.thevirtualblackhole.com/virtual-tech/using-powershell-to-get-content-from-a-file – view page – cached On my quest for PowerShell knowledge I was working on a script to rescan HBA’s and then to list the paths to the datastores but, I only wanted the script to run on certain specific hosts at a time…. Read moreOn my quest for PowerShell knowledge I was working on a script to rescan HBA’s and then to list the paths to the datastores but, I only wanted the script to run on certain specific hosts at a time. Usually the rule is when you add storage or paths to an ESX host you would do this to all hosts in the cluster at the same time and could use PowerShell to list the members of a cluster to work with but I was exploring the option of creating a list of the ESX hosts that I wanted the script to run on and have that list saved in a file. Using the “get-content” cmdlet, I was able to do just that. The only other things was the “foreach” loop, when reading the content of a file, you need to use “foreach-object” cmdlet. Below is an example of the code to read the serverlist.txt file and then use that information to rescan and then refresh the HBA’s. View page [...]
December 8th, 2009 10:01 am
Social comments and analytics for this post…
This post was mentioned on Twitter by sbeaver: New Blog Post: Using PowerShell To Get Content From a File — http://bit.ly/6uV5Tl...