Hi Jordon,
I think the error you are getting might be because you haven't connected to a cluster before attempting to use the New-NcVol cmdlet. You could try something like this basic example, if the user doesn't enter the input parameters when invoking the script they will be prompted for the input.
Param(
[Parameter(Mandatory=$True, HelpMessage="The Cluster name or IP Address")]
[String]$Cluster,
[Parameter(Mandatory=$True, HelpMessage="The vserver name")]
[String]$VserverName,
[Parameter(Mandatory=$True, HelpMessage="The volume name")]
[String]$VolumeName,
[Parameter(Mandatory=$True, HelpMessage="The volume size in GB")]
[Int]$SizeGB,
[Parameter(Mandatory=$False, HelpMessage="The aggregate name")]
[String]$JunctionPath,
[Parameter(Mandatory=$True, HelpMessage="The aggregate name")]
[String]$AggregateName,
[Parameter(Mandatory=$False, HelpMessage="The space reserve")]
[ValidateSet("none","file","volume")]
[String]$SpaceReserve="none",
[Parameter(Mandatory=$False, HelpMessage="The security style")]
[ValidateSet("mixed","ntfs","unix")]
[String]$SecurityStyle,
[Parameter(Mandatory=$True, HelpMessage="The Credential to connect to the cluster")]
[System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
#'Import the PSTK.
#'------------------------------------------------------------------------------
[String]$moduleName = "DataONTAP"
Try{
Import-Module -Name $moduleName
Write-Host "Imported module ""$moduleName"""
}Catch{
Write-Warning -Message $("Failed importing module ""$moduleName"". Error " + $_.Exception.Message)
Break;
}
#'------------------------------------------------------------------------------
#'Connect to the cluster.
#'------------------------------------------------------------------------------
Try{
Connect-NcController -Name $Cluster -HTTPS -Credential $Credential -ErrorAction Stop | Out-Null
Write-Host "Connected to cluster ""$Cluster"""
}Catch{
Write-Warning -Message $("Failed connecting to cluster ""$Cluster"". Error " + $_.Exception.Message)
Break;
}
#'------------------------------------------------------------------------------
#'Set the junction path if not provided.
#'------------------------------------------------------------------------------
If([String]::IsNullOrEmpty($JunctionPath)){
[String]$JunctionPath = "/$VolumeName"
}
#'------------------------------------------------------------------------------
#'Create the volume.
#'------------------------------------------------------------------------------
[String]$command = $("New-NcVol -Name $VolumeName -Aggregate $AggregateName -JunctionPath $JunctionPath -Size " + $SizeGB + "g -SpaceReserve $SpaceReserve ")
If($SecurityStyle){
[String]$command += "-SecurityStyle $SecurityStyle "
}
[String]$command += "-VserverContext $VserverName -ErrorAction Stop"
Try{
Invoke-Expression -Command $Command -ErrorAction Stop | Out-Null
Write-Host "Executed Command`: $command"
Write-Host $("Created Volume ""$VolumeName"" of size " + $SizeGB + "G on vserver ""$VserverName""")
}Catch{
Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
Write-Warning -Message $("Failed creating Volume ""$VolumeName"" of size " + $SizeGB + " on vserver ""$VserverName""")
}
#'------------------------------------------------------------------------------
As an example of running the script:
PS D:\Scripts\PowerShell\Projects\CreateVolume> $credential = Get-Credential -Credential admin
PS D:\Scripts\PowerShell\Projects\CreateVolume> .\CreateVolume.ps1 -Cluster cluster1.testlab.local -VserverName vserver1
-VolumeName volume1 -SizeGB 10 -AggregateName node1_aggr1 -Credential $credential
Imported module "DataONTAP"
Connected to cluster "cluster1.testlab.local"
Executed Command: New-NcVol -Name volume1 -Aggregate node1_aggr1 -JunctionPath /volume1 -Size 10g -SpaceReserve none -VserverContext vserver1 -ErrorAction Stop
Created Volume "volume1" of size 10G on vserver "vserver1"
EG cli result:
cluster1::*> vol show -vserver vserver1 -volume volume1 -fields volume, junction-path, aggregate, size, space-guarantee, security-style, state
vserver volume aggregate size state security-style junction-path space-guarantee
-------- ------- ----------------- ---- ------ -------------- ------------- ---------------
vserver1 volume1 node1_aggr1 10GB online ntfs /volume1 none
Note: if you don't specifiy the volume security style the new volume will automatically inherit the security style of the vservers root volume.
There are many more options you might want to consider when creating volumes, EG dedupe, export policies etc. This is just an example to get you started, modify to meet your requirements. Hope this helps
/Matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.