Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
Hello,
I'd like to build a script which can create FlexVols and qtrees from a list of hostnames. The names of the vols and the qtrees will be based on the hostnames of the servers which will connect to the LUNs contained within the qtrees.
Are you able to give me some pointers on where I should start please?
Thanks
Solved! See The Solution
Yeah, there is some PowerShell magic there.
Hope that helps!
Would something like this work:
# Define Hostnames
$host1 = computer1
$host2 = computer2
$host3 = computer3
$hosts = $host1, $host2, $host3
# Load the DataONTAP Module
Import-Module DataONTAP
# Connect to the filer
Connect-NaController filer1
# Create FlexVol
$hosts : ForEach-Object < New-NaVol -Name "$hosts_BOOT" -Aggregate aggr_test -SpaceReserve none -Size 100g >
# Create Qtree
$hosts : ForEach-Object < New-NaQtree "/vol/$hosts_BOOT/$hosts_boot.q"
Certainly! You're pretty good on the structure too. In case you need some help with the syntax:
Import-Module dataontap
$hosts = "foo","bar","baz"
Connect-NaController 10.61.169.28
$hosts | foreach {
New-NaVol "$($_)_boot" -Aggregate aggr0 -SpaceReserve none -Size 10g
New-NaQtree "/vol/$($_)_boot/$($_)_boot.q"
}
Another tip, if you aren't sure what a cmdlet will do, most cmdlets (in the toolkit or otherwise) support the "-WhatIf" switch which will show you the operation it will perform, but won't actually do anything.
Cheers,
Eric
Thanks Eric, really appreciate the reply and pleased I wasn't too wide of the mark.
1. Will the commands be run in order? For example, after the 'foo_boot' volume has been created, will the 'foo_boot.q' qtree be created inside it?
2. How does the '$($_)' part of the script work? I was thinking I'd have to put in the '$hosts' variable?
Thanks for the '-WhatIf' tip.
Cheers
Yeah, there is some PowerShell magic there.
Hope that helps!
Eric,
That's brilliant, thanks very much for your help and I appreciate the time you've given to answer.
Thanks, Ty
......another thought, if I wanted to read in the list of hosts from a text file as opposed to defining a list within the script, can I do that?
I've got the hosts listed in an Excel spreadsheet I'm thinking if I can export this out to a text file and read it into the script it would save my typing.
Thanks
Of course!
Get-Content works great for a simple file with one item per line:
PS C:\> $hosts = get-content C:\temp\hosts.txt
And if you have more sophisticated data, Import-Csv can read CSV files (easily exported from Excel). "help Get-Content" or "help Import-Csv" will tell you more.
Thanks once again Eric