The following snippet creates a directory and shares that directory:
$path = 'C:TempWmiPermissions'
New-Item $path -ItemType Directory
$params = @{
ClassName = 'Win32_Share'
MethodName = 'Create'
Arguments = @{
Name = 'WmiPerms'
Path = $path
Type = [UInt32]0
}
}
Invoke-CimMethod @params
The Create method used here will fail if the argument for Type is not correctly defined as a UInt32 value. PowerShell will otherwise use Int32 for a value of 0.
The requirement for UInt32, in this case, may be viewed by exploring the parameters required for the method:
PS> (Get-CimClass Win32_Share).CimClassMethods['Create'].Parameters | Where-Object Name -eq Type
Name CimType Qualifiers ReferenceClassName
---- ------- ---------- ------------------
Type UInt32 {ID, In, MappingStrings}