General Discussion

PowerShell Query

Alex78
2,523 Views

Hello, I have a PowerShell Script 

 

$source_vservers = Get-NcCifsServer -Controller $src
$source_vservers = $source_vservers.CifsServer

ForEach ($source_vserver in $source_vservers) {

Get-NcVol -Controller $src -VserverContext $source_vserver

}

 

I got allways this output:

 

Get-NcVol : Specified vserver not found
In Zeile:6 Zeichen:1
+ Get-NcVol -Controller $src -VserverContext $source_vserver

 

When I check the $source_vserver, I got an output from one SVM.

When I set the $source_verserver = "SVMname", the command works.

 

Has anyone an idea how can i fix the problem?

 

Best regards

Alex

4 REPLIES 4

mbeattie
2,495 Views

Hi Alex

 

Try something like this...

 

$cluster     = Read-Host -Prompt "Please enter the cluster name or IP Address"
$credentials = Get-Credential -Credential admin
Connect-NcController -Name $cluster -HTTPS -Credential $credentials
$svms = Get-NcCifsServer
ForEach($svm in $svms.CifsServer){
   Get-NcVol -VserverContext $svm.Name
}

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

mbeattie
2,493 Views

Hi Alex,

 

Actually i suspect the issue is caused by the CIFS server name being in uppercase whereas the SVM name in ONTAP is lowercase. For example if you wanted to query a cluster for all SVM's that were running CIFS and display the volume names (excluding the root volume)...

 

$cluster     = Read-Host -Prompt "Please enter the cluster name or IP Address"
$credentials = Get-Credential -Credential admin
Connect-NcController -Name $cluster -HTTPS -Credential $credentials | Out-Null
$svms = Get-NcCifsServer
ForEach($svm in $svms.CifsServer){
   $volumes = Get-NcVol -VserverContext $($svm.ToLower())
   ForEach($volume In $volumes){
      If($volume.JunctionPath -ne "/"){
         Write-Host $($volume.Vserver + "," + $volume.Name)
      }
   }
}

 

Example output:

 

Please enter the cluster name or IP Address: cluster1.testlab.local
vserver1,cifs_data_001
vserver1,cifs_data_002
vserver1,cifs_data_003

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Alex78
2,482 Views

Thank you very much. 

I have found another solution, which works better:

 

 

Get-NcVserver -Controller $src | Where { $_.AllowedProtocols -eq "cifs" }

 

 

Best regards

Alex

mbeattie
2,470 Views

Hi Alex,

 

No problem, however please be aware that by default when you create an SVM the allowed protocols attribute will enable all protocols (nfs,cifs,fcp,iscsi,ndmp). The allow protocols field doesn't necessarily mean the CIFS service is actually configured and running on the vserver. If your objective is to show data volumes for SVM's that are running CIFS then using the "Get-NcCifsServer" cmdlet would appropriate. If however you have used the allowed protocols attribute to restrict the SVM's protocols to only the services that are actually running in your environment then that would be a much easier way to filter the results.

 

/Matt

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public