0

How can i get this to show me who's using the shares on our NETAPP.

$computer = "gozer"
$namespace = "root\CIMV2"    # note to self find out if this is correct
$userSessions = Get-WmiObject -class Win32_ServerConnection -computername $computer -namespace $namespace

if($userSessions -ne $null)
{
    Write-Host "The following users are connected to your PC: "
    foreach ($userSession in $userSessions)
    {
        $userDetails = [string]::Format("User {0} from machine {1} on share: {2}", 
        $userSession.UserName, $userSession.ComputerName, $userSession.ShareName)
        Write-Host $userDetails
    }    
    Read-Host
}
exit

the error i receive when i run this pointing at a NETAPP SVM is:

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At C:\test\whos-using-the-share.ps1:3 char:17
+ $userSessions = Get-WmiObject -class Win32_ServerConnection -computername $compu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
JosefZ
  • 28,460
  • 5
  • 44
  • 83
rob_h
  • 1
  • 1
  • 2
    The W in WMI stands for Windows. NETAPP SVMs do not run Windows. I'll let you do the math :-) – Mathias R. Jessen Jul 01 '21 at 15:50
  • @MathiasR.Jessen That's not really correct. CIM and WMI are the same thing, and CIM has been an open industry standard for over 20 years. Any OS can support `Get-WMIObject`/`Get-CimInstance`. It's two names for an identical protocol for WBEM. It is more rare for non-MS systems to support it, but that doesn't mean they *can't*. That said, only Windows is likely to support the `Win32_ServerConnection` class, and the namespaces and classes a given system does support will vary by the provider. – Bacon Bits Jul 01 '21 at 18:59
  • Mathias, thanks for the quick response, even after changing to CIM command script errors out. i'm now getting this and this is very frustrating!: Get-CimInstance : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". – rob_h Jul 06 '21 at 14:38

0 Answers0