Subscribe

Powershell Close-NcCifsSessionFile not accepting value from Get-NcCifsSessionFile

[ Edited ]

Hi Folk,

 

I'm trying to automate the closing/removing of CIFS file locks, and I'm running into problems with datat ypes.

 

In particular, I do a Get-NcCifsSessionFile which gives me a set of CIFSSessionFile objects, but when I try to pass the SessionID from one of those objects to the Close-NcCifsSessionFile it tells me value is too large for an INT64 (the close session applet is expecting an INT64, but the Get is returning a Decimal)

 

My code is essentially:

 

 

 

$SearchPath = "*CBR1PSCM01 TSM errors.xlsx" 

# get a list of files open on cluster
$CIFSSessionFileTemplate = Get-NcCifsSessionFile -Template
$CIFSSessionFileTemplate.Path = $SearchPath
$Files = Get-NcCifsSessionFile -Query $CIFSSessionFileTemplate


foreach ($f in $FileList)
    {
    Close-NcCifsSessionFile -Node $f.Node  -FileId $f.FileId -SessionId $f.SessionId -ConnectionId $f.ConnectionId 
    }

 

 

It I look at the type of the SessionId, it's decimal, and from what I see it IS too long for an INT64

 

#24 PS3 H:\> $f.SessionId.GetType()
IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Decimal System.ValueType
#23 PS3 H:\> Close-NcCifsSessionFile -Node $f.Node  -FileId $f.FileId -SessionId $f.SessionId -ConnectionId $f.ConnectionId 
Close-NcCifsSessionFile : Cannot bind parameter 'SessionId'. Cannot convert value "14120473681666951262" to type "System.Int64". Error: "Value was either too large or too small for an Int64."

think this was working on an earlier version of OnTap, but it's not working with 9.2P1

 

 

NAS:     ONTAP 9.2P1

Toolkit:  V4.4  (DataONTAP module is 4.2.0)

PowerShell: 5.1

 

 

Is this a problem with the module?

 

(I'd be happy to know if there's another way to do it also!)

 

 

Cheers,


Stuart

 

 

Re: Powershell Close-NcCifsSessionFile not accepting value from Get-NcCifsSessionFile

Hello @OZWALKERZ,

 

Why not just pipe the object into Close-NcCifsSessionFile?

 

Get-NcCifsSessionFile -Query @{ Path = $SearchPath } | Close-NcCifsSessionFile -Confirm:$false

Hope that helps!

 

Andrew

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

Re: Powershell Close-NcCifsSessionFile not accepting value from Get-NcCifsSessionFile

Good thought, but no.

 

 

 

 

 

#14 PS4 H:\> Get-NcCifsSessionFile -Query @{ Path = $SearchPath } 

Path                                                                           ConnectionId Vserver
----                                                                           ------------ -------
<somedir>\CBR1PSCM01 TSM errors.xlsx                                                 134041239 <some vserver>

 

 

 

 

 

#15 PS4 H:\> Get-NcCifsSessionFile -Query @{ Path = $SearchPath }  | Close-NcCifsSessionFile -Confirm:$false
Close-NcCifsSessionFile : Failed to close an open file on CIFS server "<some vserver>". Reason: The parameters "-connection-id" and "-session-id" are required when "-file-id" is specified.
At line:1 char:57
+ Get-NcCifsSessionFile -Query @{ Path = $SearchPath }  | Close-NcCifsSessionFile  ...
+                                                         ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (prodnas.production.prod:NcController) [Close-NcCifsSessionFile], EAPIERROR
    + FullyQualifiedErrorId : ApiException,DataONTAP.C.PowerShell.SDK.Cmdlets.Cifs.CloseNcCifsSessionFile

 

I had already tried

 

Close-NcCifsSessionFile $f

 

with no luck, so I tried

 

$f | Close-NcCifsSessionFile

 

and they both get the same error that your suggestion got above

 

 

 

 

My guess is that the  Close-NcCifsSessionFile is expecting an INT value for the SessionId, but the Get-NcCifsSessionFile is returning a  Decimal - perhaps the get applet was updated to return a decimal, but the close applet wasn't updated to accept it?

 

 

Cheers,


Stuart

Re: Powershell Close-NcCifsSessionFile not accepting value from Get-NcCifsSessionFile

Interesting, I had (successfully) tested the pipe method with ONTAP 9.1, but don't readily have a 9.2 system available.  I'll see if I can get something deployed and tested in the near future.

 

I suspect this may be a bug either in the PowerShell module or ZAPI itself.

 

Andrew

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

Re: Powershell Close-NcCifsSessionFile not accepting value from Get-NcCifsSessionFile

Thanks Andrew!

 

I had also thought it might be bug Smiley Happy

 

Is there a method for raising a bug for the PowerShell module, or the API? (Or does that have to come from you guys?)

 

 

Cheers,

Stuart

Re: Powershell Close-NcCifsSessionFile not accepting value from Get-NcCifsSessionFile

Not sure if there is a way for someone external to directly create a bug, but I can take care of it.

 

Happy to send you some stickers for a "bug bounty", just PM me your mailing address!

 

Andrew

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