Win32_Share

Win32 Share
root/cimv2dynamickey : Name

The Win32_Share class represents a shared resource on a computer system running Windows. This may be a disk drive, printer, interprocess communication, or other sharable device. For more information about retrieving WMI classes, see Retrieving a Class.

On this page

Main example

List instances

# All instances of Win32_Share, with the main properties
Get-CimInstance -ClassName Win32_Share |
    Select-Object -Property Name, Path, Description, Type

Examples

Filter with WQL

# WQL filter evaluated by the provider: Type = 0 (Disk Drive)
Get-CimInstance -ClassName Win32_Share -Filter 'Type = 0' |
    Select-Object -Property Name, Path, Description, Type

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Decode numeric values

# Lookup table for Type (values documented by Microsoft)
$typeName = @{
    0 = 'Disk Drive'
    1 = 'Print Queue'
    2 = 'Device'
    3 = 'IPC'
    2147483648 = 'Disk Drive Admin'
    2147483649 = 'Print Queue Admin'
    2147483650 = 'Device Admin'
    2147483651 = 'IPC Admin'
}

Get-CimInstance -ClassName Win32_Share |
    Select-Object -Property @(
        'Name'
        'Path'
        'Description'
        @{ Name = 'Type'; Expression = { $typeName[[int]$_.Type] } }
    )

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    Get-CimInstance -CimSession $cimSession -ClassName Win32_Share |
        Select-Object -Property Name, Path, Description, Type
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_Share
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

# Methods of the class
$cimClass.CimClassMethods |
    Select-Object -Property Name, ReturnType

Properties

10 of 10 properties
NameTypeAccessDescription
AccessMaskuint32read

This property is obsolete and is no longer used. Use the Win32_Share.GetAccessMask method instead. The value of the AccessMask property is set to null by WMI. For more information about setting access when a share is created, see the Create method.

Code
# Value of AccessMask for each instance
Get-CimInstance -ClassName Win32_Share -Property Name, AccessMask |
    Select-Object -Property Name, AccessMask
AllowMaximumbooleanread

Number of concurrent users for this resource has been limited. If True, the value in the MaximumAllowed property is ignored.

Code
# Value of AllowMaximum for each instance
Get-CimInstance -ClassName Win32_Share -Property Name, AllowMaximum |
    Select-Object -Property Name, AllowMaximum
Captionstringread

A short textual description of the object.

Code
# Value of Caption for each instance
Get-CimInstance -ClassName Win32_Share -Property Name, Caption |
    Select-Object -Property Name, Caption
Descriptionstringread

A textual description of the object.

Code
# Value of Description for each instance
Get-CimInstance -ClassName Win32_Share -Property Name, Description |
    Select-Object -Property Name, Description
InstallDatedatetimeread

Indicates when the object was installed. Lack of a value does not indicate that the object is not installed.

Code
# Value of InstallDate for each instance
# CIM cmdlets already return a DateTime object: no conversion is needed
Get-CimInstance -ClassName Win32_Share -Property Name, InstallDate |
    Select-Object -Property Name, InstallDate
MaximumAlloweduint32read

Limit on the maximum number of users allowed to use this resource concurrently. The value is only valid if the AllowMaximum property is set to FALSE.

Code
# Value of MaximumAllowed for each instance
Get-CimInstance -ClassName Win32_Share -Property Name, MaximumAllowed |
    Select-Object -Property Name, MaximumAllowed
Name keystringread

Alias given to a path set up as a share on a computer system running Windows.

Windows 2008 example: "\SERVER01\public" - Windows Server 2008 requires that you place the UNC in the name.

Code
# Value of Name for each instance
Get-CimInstance -ClassName Win32_Share -Property Name |
    Select-Object -Property Name
Pathstringread

Local path of the Windows share.

Example: "C:\Program Files"

Code
# Value of Path for each instance
Get-CimInstance -ClassName Win32_Share -Property Name, Path |
    Select-Object -Property Name, Path
Statusstringread

String that indicates the current status of the object. Operational and non-operational status can be defined. Operational status can include "OK", "Degraded", and "Pred Fail". "Pred Fail" indicates that an element is functioning properly, but is predicting a failure (for example, a SMART-enabled hard disk drive).

Non-operational status can include "Error", "Starting", "Stopping", and "Service". "Service" can apply during disk mirror-resilvering, reloading a user permissions list, or other administrative work. Not all such work is online, but the managed element is neither "OK" nor in one of the other states.

Values include the following:

Values (12)
ValueLabelDescription
OKOK
ErrorError
DegradedDegraded
UnknownUnknown
Pred FailPred Fail
StartingStarting
StoppingStopping
ServiceService
StressedStressed
NonRecoverNonRecover
No ContactNo Contact
Lost CommLost Comm
Code
# Value of Status for each instance
Get-CimInstance -ClassName Win32_Share -Property Name, Status |
    Select-Object -Property Name, Status
Typeuint32read

Type of resource being shared. Types include: disk drives, print queues, interprocess communications (IPC), and general devices.

Values (8)
ValueLabelDescription
0Disk Drive
1Print Queue
2Device
3IPC
2147483648Disk Drive Admin
2147483649Print Queue Admin
2147483650Device Admin
2147483651IPC Admin
Code
# Value of Type for each instance
# Lookup table for Type (values documented by Microsoft)
$typeName = @{
    0 = 'Disk Drive'
    1 = 'Print Queue'
    2 = 'Device'
    3 = 'IPC'
    2147483648 = 'Disk Drive Admin'
    2147483649 = 'Print Queue Admin'
    2147483650 = 'Device Admin'
    2147483651 = 'IPC Admin'
}
Get-CimInstance -ClassName Win32_Share -Property Name, Type |
    Select-Object -Property @(
        'Name'
        @{ Name = 'Type'; Expression = { $typeName[[int]$_.Type] } }
    )

Methods

Create static#

Class method that initiates sharing for a server resource.

uint32 Create(
    [in] string Path,
    [in] string Name,
    [in] uint32 Type,
    [in] uint32 MaximumAllowed,
    [in] string Description,
    [in] string Password,
    [in] Win32_SecurityDescriptor Access
);

Parameters

ParameterTypeDirectionDescription
Pathstringin

Local path of the Windows share.

Example, "C:\Program Files".

Namestringin

Passes the alias to a path set up as a share on a computer system running Windows.

Example, "public".

Typeuint32in

Passes the type of resource being shared. Types includes disk drives, print queues, interprocess communications (IPC), and general devices. Can be one of the following values.

MaximumAlloweduint32in

Limit on the maximum number of users allowed to concurrently use this resource.

Example: 10. This parameter is optional.

Descriptionstringin

Optional comment to describe the resource being shared. This parameter is optional.

Passwordstringin

Password (when the server is running with share-level security) for the shared resource. If the server is running with user-level security, this parameter is ignored. This parameter is optional.

AccessWin32_SecurityDescriptorin

Security descriptor for user level permissions. A security descriptor contains information about the permissions, owner, and access capabilities of the resource. If this parameter is not supplied or is NULL, then Everyone has read access to the share. For more information, see Win32_SecurityDescriptor and Changing Access Security on Securable Objects.

Return values

ValueLabelDescription
0Success
2Access denied
8Unknown failure
9Invalid name
10Invalid level
21Invalid parameter
22Duplicate share
23Redirected path
24Unknown device or directory
25Net name not found
26..4294967295Other

Call the Create method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
$methodParameters = @{
    ClassName  = 'Win32_Share'
    MethodName = 'Create'
    Arguments  = @{
        Path           = 'C:\Share'
        Name           = 'ExampleShare'
        Type           = 0
        MaximumAllowed = 0
        Description    = 'Example'
        Password       = 'Example'
        Access         = $null
    }
    WhatIf     = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Success'
        2 = 'Access denied'
        8 = 'Unknown failure'
        9 = 'Invalid name'
        10 = 'Invalid level'
        21 = 'Invalid parameter'
        22 = 'Duplicate share'
        23 = 'Redirected path'
        24 = 'Unknown device or directory'
        25 = 'Net name not found'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

Delete #

Class method that deletes a share name from a server's list of shared resources, disconnecting connections to the shared resource.

uint32 Delete();

Return values

ValueLabelDescription
0Success
2Access denied
8Unknown failure
9Invalid name
10Invalid level
21Invalid parameter
22Duplicate share
23Redirected path
24Unknown device or directory
25Net name not found
26..4294967295Other

Call the Delete method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Share -Filter "Name = 'ExampleShare'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'Delete'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Success'
        2 = 'Access denied'
        8 = 'Unknown failure'
        9 = 'Invalid name'
        10 = 'Invalid level'
        21 = 'Invalid parameter'
        22 = 'Duplicate share'
        23 = 'Redirected path'
        24 = 'Unknown device or directory'
        25 = 'Net name not found'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

GetAccessMask #

Returns the access rights to the share held by the user or group on whose behalf the instance is returned. You should use this method in place of the AccessMask property, which is always NULL.

uint32 GetAccessMask();

Return values

ValueLabelDescription
1FILE_LIST_DIRECTORYGrants the right to read data from the file. For a directory, this value grants the right to list the contents of the directory.
2FILE_ADD_FILEGrants the right to write data to the file. For a directory, this value grants the right to create a file in the directory.
4FILE_ADD_SUBDIRECTORYGrants the right to append data to the file. For a directory, this value grants the right to create a subdirectory.
8FILE_READ_EAGrants the right to read extended attributes.
16FILE_WRITE_EAGrants the right to write extended attributes.
32FILE_TRAVERSEGrants the right to execute a file. For a directory, the directory can be traversed.
64FILE_DELETE_CHILDGrants the right to delete a directory and all of the files it contains (its children), even if the files are read-only.
128FILE_READ_ATTRIBUTESGrants the right to read file attributes.
256FILE_WRITE_ATTRIBUTESGrants the right to change file attributes.
65536DELETEGrants delete access.
131072READ_CONTROLGrants read access to the security descriptor and owner.
262144WRITE_DACGrants write access to the discretionary access control list (DACL).
524288WRITE_OWNERAssigns the write owner.
1048576SYNCHRONIZESynchronizes access and allows a process to wait for an object to enter the signaled state.

Call the GetAccessMask method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Share -Filter "Name = 'ExampleShare'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'GetAccessMask'
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        1 = 'FILE_LIST_DIRECTORY'
        2 = 'FILE_ADD_FILE'
        4 = 'FILE_ADD_SUBDIRECTORY'
        8 = 'FILE_READ_EA'
        16 = 'FILE_WRITE_EA'
        32 = 'FILE_TRAVERSE'
        64 = 'FILE_DELETE_CHILD'
        128 = 'FILE_READ_ATTRIBUTES'
        256 = 'FILE_WRITE_ATTRIBUTES'
        65536 = 'DELETE'
        131072 = 'READ_CONTROL'
        262144 = 'WRITE_DAC'
        524288 = 'WRITE_OWNER'
        1048576 = 'SYNCHRONIZE'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

SetShareInfo #

Class method that sets the parameters of a shared resource.

uint32 SetShareInfo(
    [in] uint32 MaximumAllowed,
    [in] string Description,
    [in] Win32_SecurityDescriptor Access
);

Parameters

ParameterTypeDirectionDescription
MaximumAlloweduint32in

Limit on the maximum number of users allowed to use this resource concurrently.

Example: 10. This parameter is optional.

Descriptionstringin

Optional comment to describe the resource being shared.

AccessWin32_SecurityDescriptorin

Security descriptor for user-level permissions. A security descriptor contains information about the permission, owner, and access capabilities of the resource. For more information, see Win32_SecurityDescriptor.

Return values

ValueLabelDescription
0Success
2Access denied
8Unknown failure
9Invalid name
10Invalid level
21Invalid parameter
22Duplicate share
23Redirected path
24Unknown device or directory
25Net name not found
26..4294967295Other

Call the SetShareInfo method

review before running
# Warning: this method can change the system. -WhatIf shows the operation without running it.
# Target instance
$instance = Get-CimInstance -ClassName Win32_Share -Filter "Name = 'ExampleShare'"
$methodParameters = @{
    InputObject = $instance
    MethodName  = 'SetShareInfo'
    Arguments   = @{
        MaximumAllowed = 0
        Description    = 'Example'
        Access         = $null
    }
    WhatIf      = $true  # Remove this line to actually run the method
}
$result = Invoke-CimMethod @methodParameters

# With -WhatIf nothing runs and no result is returned
if ($result) {
    $returnValueName = @{
        0 = 'Success'
        2 = 'Access denied'
        8 = 'Unknown failure'
        9 = 'Invalid name'
        10 = 'Invalid level'
        21 = 'Invalid parameter'
        22 = 'Duplicate share'
        23 = 'Redirected path'
        24 = 'Unknown device or directory'
        25 = 'Net name not found'
    }
    $returnValueName[[int]$result.ReturnValue]
}

This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.

Remarks

The Win32_Share class is derived from CIM_LogicalElement.

The Create method in this class is a static method. The Delete, GetAccessMask and SetShareInfo methods are all instance methods.

Depending on your security permissions, you may not be able to retrieve all of the properties of this class. For example, AllowMaximum, MaximumAllowed, Path, and Type properties may return null. Generally speaking, Power Users and Administrators will be able to retrieve all property values.

Inheritance

Superclass chain

  1. CIM_ManagedSystemElement
  2. CIM_LogicalElement
  3. Win32_Share

Known subclasses

Requirements

Namespace
root/cimv2
Minimum client
Windows Vista
Minimum server
Windows Server 2008
Provider
CIMWin32
MOF file
CIMWin32.mof
DLL
CIMWin32.dll
Class qualifiers

Dynamic Provider("CIMWin32") UUID("{8502C4D6-5FBB-11D2-AAC1-006008C78BC7}") SupportsCreate CreateBy("Create") SupportsDelete DeleteBy("DeleteInstance") AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.