SessionState type problem with CimSession

In the process of converting a UD Community V2.8.1 dashboard to PSU 2. The UD dashboard works using Get-SmbOpenFile and Close-SmbOpenFile but PSU has an issue with Close-SmbOpenFile.

#----- Connect to file server and get list of open files -----
$Session = New-CimSession -ComputerName $Srvr.value -Authentication Kerberos -Credential $DomainAdmin
$list = Get-SmbOpenFile -CimSession $Session

#----- Create Table of open files -----
$Columns = @( 
  New-UDTableColumn -Property FileName -Title "FileName" 
  New-UDTableColumn -Property FileId -Title 'ID' 
  New-UDTableColumn -Property Path -Title 'Server File Path'
  New-UDTableColumn -Property ComputerName -Title 'Client'
  New-UDTableColumn -Property UserName -Title 'User'
  New-UDTableColumn -Property 'Close File' -Title 'Close File' -Render {
	New-UDButton -Id "$btn$($EventData.FileId)" -Text "Close" -OnClick { 
		Close-SmbOpenFile -CimSession $Session -FileId $EventData.FileId -Force
		Show-UDToast -Message "$($EventData.FileName) has been closed"
	}
  }
)
New-UDTable -Data $files -Columns $Columns -Title "Open File List" -ShowSort -Dense

Logged Error:
Jun 4, 2021 3:13 PM An error occurred: Cannot process argument transformation on parameter ‘CimSession’. Cannot convert the “UniversalDashboard.Models.SessionState” value of type “UniversalDashboard.Models.SessionState” to type “Microsoft.Management.Infrastructure.CimSession[]”.
Endpoint: 528012865573
Session: 23b098cf-d4b0-4444-b92a-e237288946b6
File:
Endpoint Start Line: 2
Endpoint End Line: 5
Stack Trace: at , : line 2

The CimSession is working since I can get the list of open files I just can’t close any. Any idea what the problem might be?

Can you try renaming your variable to something else? Like $Session → $CimSession?

I have a hunch that there is a variable conflict with something that UD is injecting.

Yep. That was it. I appreciate all the help.

1 Like