I'm trying to write a script that will mount multiple NFS exports to multiple ESX hosts. Below is the script I have been using, it will add one NFS export to a list of esx hosts.
$esx = (Get-Content servers.txt)
Do{
$Host_Name = (Read-Host "Enter the server (ex:storage-san")
$Path = (Read-Host "Enter the path (ex:/vol/vol/ds_name)")
$Name = (Read-Host "Enter the name of the datastore")
foreach($server in $esx){
$Error.Clear()
Get-VMHost $server | New-Datastore -Nfs -NfsHost $Host_Name -Path $Path -Name $Name | Out-Null
if($error.count -gt 0){$error | out-file ('c:\powershell scripts\logs\' + $server + '.txt')}
}
$add_more = Read-Host "Do you want to mount another datastore?"
}
While($add_more -eq "yes" -or $add_more -eq "y")
This script actually works OK but I can't just kick it off and walk away. If I have 10 datastores to add, I've got to wait for the current one to finish and then type in the info for the second one, etc.
I was hoping to just type all of the information upfront and kick the script off and let it go. Here's what I've added, can you see where I'm going with this?
$esx = (Get-Content servers.txt)
$num_mounts = (Read-Host "Do you have multiple mounts")
if($num_mounts -eq "yes" -or $num_mounts -eq "y")
{
$mounts = @(Read-Host "How many different mounts do you have")
#prompt me for all of the different mounts right up front and then run through the actual task of mounting them....
}
Any ideas?