Main example
List instances
# All instances of Win32_PageFile, with the main properties
Get-CimInstance -ClassName Win32_PageFile |
Select-Object -Property @(
'CSName'
'FSCreationClassName'
'Name'
'Caption'
'Description'
'Status'
'Manufacturer'
)Examples
Filter with WQL
# WQL filter evaluated by the provider: AccessMask = 1 (FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory))
Get-CimInstance -ClassName Win32_PageFile -Filter 'AccessMask = 1' |
Select-Object -Property @(
'CSName'
'FSCreationClassName'
'Name'
'Caption'
'Description'
'Status'
'Manufacturer'
)The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.
Decode numeric values
# Lookup table for AccessMask (values documented by Microsoft)
$accessMaskName = @{
1 = 'FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)'
2 = 'FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)'
4 = 'FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY (directory)'
8 = 'FILE_READ_EA'
16 = 'FILE_WRITE_EA'
32 = 'FILE_EXECUTE (file) or FILE_TRAVERSE (directory)'
64 = 'FILE_DELETE_CHILD (directory)'
128 = 'FILE_READ_ATTRIBUTES'
256 = 'FILE_WRITE_ATTRIBUTES'
65536 = 'DELETE'
131072 = 'READ_CONTROL'
262144 = 'WRITE_DAC'
524288 = 'WRITE_OWNER'
1048576 = 'SYNCHRONIZE'
}
Get-CimInstance -ClassName Win32_PageFile |
Select-Object -Property @(
'CSName'
'FSCreationClassName'
'Name'
'Caption'
'Description'
'Status'
'Manufacturer'
)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_PageFile |
Select-Object -Property @(
'CSName'
'FSCreationClassName'
'Name'
'Caption'
'Description'
'Status'
'Manufacturer'
)
} 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_PageFile
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, Flags
# Methods of the class
$cimClass.CimClassMethods |
Select-Object -Property Name, ReturnTypeProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| AccessMask# | uint32 | read | Bitmask that represents the access rights required to access or perform specific operations on the file. For values, see File and Directory Access Rights Constants. Values (14)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| Archive# | boolean | read | If True, the file should be archived. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Caption# | string | read | A short textual description of the object. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Compressed# | boolean | read | If True, the file is compressed. Code | |||||||||||||||||||||||||||||||||||||||||||||
| CompressionMethod# | string | read | Free-form string that indicates the algorithm or tool used to compress the logical file. If the compression scheme is unknown or not described, use "Unknown". If the logical file is compressed, but the compression scheme is unknown or not described, use "Compressed". If the logical file is not compressed, use "Not Compressed". Code | |||||||||||||||||||||||||||||||||||||||||||||
| CreationClassName# key | string | read | Name of the class. Code | |||||||||||||||||||||||||||||||||||||||||||||
| CreationDate# | datetime | read | Date and time of the file's creation. Code | |||||||||||||||||||||||||||||||||||||||||||||
| CSCreationClassName# key | string | read | Class of the computer system. Code | |||||||||||||||||||||||||||||||||||||||||||||
| CSName# key | string | read | Name of the computer system. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Description# | string | read | A textual description of the object. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Drive# | string | read | Drive letter (including the colon that follows the drive letter) of the file. This property is inherited from CIM_LogicalFile. Example: "c:" Code | |||||||||||||||||||||||||||||||||||||||||||||
| EightDotThreeFileName# | string | read | DOS-compatible file name. Example: "c:\progra~1" Code | |||||||||||||||||||||||||||||||||||||||||||||
| Encrypted# | boolean | read | If True, the file is encrypted. Code | |||||||||||||||||||||||||||||||||||||||||||||
| EncryptionMethod# | string | read | Free-form string that identifies the algorithm or tool used to encrypt a logical file. If the encryption scheme is not indulged (for security reasons, for example), use "Unknown". If the file is encrypted, but either its encryption scheme is unknown or not disclosed, use "Encrypted". If the logical file is not encrypted, use "Not Encrypted". Code | |||||||||||||||||||||||||||||||||||||||||||||
| Extension# | string | read | File name extension without the preceding period (dot). Example: "txt", "mof", "mdb" Code | |||||||||||||||||||||||||||||||||||||||||||||
| FileName# | string | read | File name without the file name extension. Example: "MyDataFile" Code | |||||||||||||||||||||||||||||||||||||||||||||
| FileSize# | uint64 | read | Size of the file, in bytes. For more information about using uint64 values in scripts, see Scripting in WMI). Unit: bytes Code | |||||||||||||||||||||||||||||||||||||||||||||
| FileType# | string | read | Descriptor that represents the file type indicated by the Extension property. Code | |||||||||||||||||||||||||||||||||||||||||||||
| FreeSpace# | uint32 | read | Space available in the paging file. The operating system can enlarge the paging file as necessary, up to the limit imposed by the user. This property shows the difference between the size of current committed memory and the current size of the paging file; it does not show the largest possible size of the paging file. Unit: megabytes Code | |||||||||||||||||||||||||||||||||||||||||||||
| FSCreationClassName# key | string | read | Class of the file system. Code | |||||||||||||||||||||||||||||||||||||||||||||
| FSName# key | string | read | Name of the file system. Code | |||||||||||||||||||||||||||||||||||||||||||||
| InitialSize# | uint32 | read | Initial size of the page file. Unit: megabytes Code | |||||||||||||||||||||||||||||||||||||||||||||
| InstallDate# | datetime | read | Indicates when the object was installed. Lack of a value does not indicate that the object is not installed. Code | |||||||||||||||||||||||||||||||||||||||||||||
| InUseCount# | uint64 | read | Number of "file opens" that are currently active against the file. For more information about using uint64 values in scripts, see Scripting in WMI). Code | |||||||||||||||||||||||||||||||||||||||||||||
| LastAccessed# | datetime | read | Date and time the file was last accessed. Code | |||||||||||||||||||||||||||||||||||||||||||||
| LastModified# | datetime | read | Date and time the file was last modified. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Manufacturer# | string | read | Manufacturer string from the version resource (if one is present). Code | |||||||||||||||||||||||||||||||||||||||||||||
| MaximumSize# | uint32 | read | Maximum size of the page file as set by the user. The operating system will not allow the page file to exceed this limit. Unit: megabytes Code | |||||||||||||||||||||||||||||||||||||||||||||
| Name# | string | read | Name of the page file. Example: "C:\PAGEFILE.SYS" Code | |||||||||||||||||||||||||||||||||||||||||||||
| Path# | string | read | Path of the file including the leading and trailing backslashes. Example: "\windows\system\" Code | |||||||||||||||||||||||||||||||||||||||||||||
| Readable# | boolean | read | If True, the file can be read. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Status# | string | read | String that indicates the current status of the object. Values include the following: Values (12)
Code | |||||||||||||||||||||||||||||||||||||||||||||
| System# | boolean | read | If True, the file is a system file. Code | |||||||||||||||||||||||||||||||||||||||||||||
| Version# | string | read | Version string from the version resource (if one is present). Code | |||||||||||||||||||||||||||||||||||||||||||||
| Writeable# | boolean | read | If True, the file can be written. Code |
Methods
ChangeSecurityPermissions #
Class method that changes the security permissions for the logical file specified in the object path.
uint32 ChangeSecurityPermissions([in] Win32_SecurityDescriptor SecurityDescriptor, [in] uint32 Option);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| SecurityDescriptor | Win32_SecurityDescriptor | in | Expression that resolves to an instance of Win32_SecurityDescriptor. This descriptor contains new security permissions for the instance of Win32_PageFile. |
| Option | uint32 | in | Security privilege to be modified. For example, to change the owner and discretionary access control list (DACL) security, use:
-or-
|
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | The request is successful. |
| 2 | Access Denied | Access is denied. |
| 8 | Unspecified failure | An unspecified failure occurred. |
| 9 | Invalid object | The specified name is not valid. |
| 10 | Object already exists | The specified object already exists. |
| 11 | File system not NTFS | The file system is not an NTFS file system. |
| 12 | Platform not NT/Windows 2000 | The platform is not Windows. |
| 13 | Drive not the same | The drive is not the same. |
| 14 | Directory not empty | The directory is not empty. |
| 15 | Sharing violation | There is a sharing violation. |
| 16 | Invalid start file | The specified start file is not valid. |
| 17 | Privilege not held | A privilege required for the operation is missing. |
| 21 | Invalid parameter | A specified parameter is not valid. |
Call the ChangeSecurityPermissions 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'ChangeSecurityPermissions'
Arguments = @{
SecurityDescriptor = $null
Option = 1
}
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 = 'Unspecified failure'
9 = 'Invalid object'
10 = 'Object already exists'
11 = 'File system not NTFS'
12 = 'Platform not NT/Windows 2000'
13 = 'Drive not the same'
14 = 'Directory not empty'
15 = 'Sharing violation'
16 = 'Invalid start file'
17 = 'Privilege not held'
21 = 'Invalid parameter'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
ChangeSecurityPermissionsEx #
Class method that changes the security permissions for the logical file specified in the object path.
uint32 ChangeSecurityPermissionsEx(
[in] Win32_SecurityDescriptor SecurityDescriptor,
[in] uint32 Option,
[out] string StopFileName,
[in] string StartFileName,
[in] boolean Recursive
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| SecurityDescriptor | Win32_SecurityDescriptor | in | Expression that resolves to an instance of Win32_SecurityDescriptor. This parameter contains new security permissions for the instance of Win32_PageFile. |
| Option | uint32 | in | Security privilege to be modified. For example, to change the owner and discretionary access control list (DACL) security, use the following:
-or-
|
| StopFileName | string | out | Name of the file or directory where the ChangeSecurityPermissionsEx method failed. This parameter is NULL if the method succeeds. |
| StartFileName | string | in | Names the child file or directory to use as a starting point for ChangeSecurityPermissionsEx. Typically, the *StartFileName* parameter is the *StartFileName* parameter that specifies the file or directory where an error occurred from the previous method call. If this parameter is null, the operation is performed on the file or directory specified in the ExecMethod call. |
| Recursive | boolean | in | If true, the change of ownership is applied recursively to files and directories in the directory specified by the CIM_LogicalFile instance. Note: For file instances, the *Recursive* parameter is ignored. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | Success | The request is successful. |
| 2 | Access Denied | Access is denied. |
| 8 | Unspecified failure | An unspecified failure occurred. |
| 9 | Invalid object | The name specified is not valid. |
| 10 | Object already exists | The specified object already exists. |
| 11 | File system not NTFS | The file system is not an NTFS file system. |
| 12 | Platform not NT/Windows 2000 | The platform is not Windows. |
| 13 | Drive not the same | The drive is not the same. |
| 14 | Directory not empty | The directory is not empty. |
| 15 | Sharing violation | There is a sharing violation. |
| 16 | Invalid start file | The specified start file is not valid. |
| 17 | Privilege not held | A privilege required for the operation is missing. |
| 21 | Invalid parameter | A specified parameter is not valid. |
Call the ChangeSecurityPermissionsEx 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'ChangeSecurityPermissionsEx'
Arguments = @{
SecurityDescriptor = $null
Option = 1
StartFileName = 'Example'
Recursive = $false
}
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 = 'Unspecified failure'
9 = 'Invalid object'
10 = 'Object already exists'
11 = 'File system not NTFS'
12 = 'Platform not NT/Windows 2000'
13 = 'Drive not the same'
14 = 'Directory not empty'
15 = 'Sharing violation'
16 = 'Invalid start file'
17 = 'Privilege not held'
21 = 'Invalid parameter'
}
$returnValueName[[int]$result.ReturnValue]
$result.StopFileName
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Compress #
Class method that compresses the logical file (or directory) specified in the object path.
uint32 Compress();Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the Compress 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Compress'
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
CompressEx #
Class method that compresses the logical file (or directory) specified in the object path.
uint32 CompressEx(
[out] string StopFileName,
[in] string StartFileName,
[in] boolean Recursive
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| StopFileName | string | out | Name of the file or directory where the CompressEx method failed. This parameter is null if the method succeeds. |
| StartFileName | string | in | Names the child file or directory to use as a starting point for CompressEx. The *StartFileName* parameter is typically the *StopFileName* parameter specifying the file or directory at which an error occurred from the previous method call. If this parameter is NULL, the operation is performed on the file or directory specified in the ExecMethod call. |
| Recursive | boolean | in | If true, the change of ownership will be applied recursively to the files and directories within the directory specified by the CIM_LogicalFile instance. Note: For file instances, the *Recursive* parameter is ignored. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the CompressEx 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'CompressEx'
Arguments = @{
StartFileName = 'Example'
Recursive = $false
}
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
$result.StopFileName
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Copy #
Class method that copies the logical file or directory specified in the object path to the location specified by the input parameter.
uint32 Copy([in] string FileName);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| FileName | string | in | Fully qualified name of the copy of the file (or directory). Example: c:\temp\newdirectory |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the Copy 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Copy'
Arguments = @{ FileName = 'Example' }
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
CopyEx #
Class method that copies the logical file or directory specified in the object path to the location specified by the FileName parameter.
uint32 CopyEx(
[in] string FileName,
[out] string StopFileName,
[in] string StartFileName,
[in] boolean Recursive
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| FileName | string | in | Fully qualified name of the copy of the file (or directory). Example: c:\temp\newdirectory |
| StopFileName | string | out | Name of the file or directory where the CopyEx method failed. This parameter is null if the method succeeds. |
| StartFileName | string | in | Names the child file or directory to use as a starting point for CopyEx. The *StartFileName* parameter is typically the *StopFileName* parameter specifying the file or directory at which an error occurred from the previous method call. If this parameter is NULL, the operation is performed on the file or directory specified in the ExecMethod call. |
| Recursive | boolean | in | If true, the change of ownership will be applied recursively to the files and directories within the directory specified by the CIM_LogicalFile instance. Note: For file instances, the *Recursive* parameter is ignored. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the CopyEx 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'CopyEx'
Arguments = @{
FileName = 'Example'
StartFileName = 'Example'
Recursive = $false
}
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
$result.StopFileName
}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 the logical file (or directory) specified in the object path.
uint32 Delete();Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
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_PageFile -Filter "CSName = 'Example'"
$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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
DeleteEx #
Class method that deletes the logical file (or directory) specified in the object path.
uint32 DeleteEx([out] string StopFileName, [in] string StartFileName);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| StopFileName | string | out | Name of the file or directory where the DeleteEx method failed. This parameter is null if the method succeeds. |
| StartFileName | string | in | Names the child file or directory to use as a starting point for DeleteEx. The *StartFileName* parameter is typically the *StopFileName* parameter that specifies the file or directory at which an error occurred from the previous method call. If this parameter is NULL, the operation is performed on the file or directory specified in the ExecMethod call. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the DeleteEx 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'DeleteEx'
Arguments = @{ StartFileName = 'Example' }
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
$result.StopFileName
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
GetEffectivePermission #
Class method that determines whether the caller has the aggregated permissions specified by the *Permission* argument not only on the file object, but on the share the file or directory resides on (if it is on a share).
boolean GetEffectivePermission([in] uint32 Permissions);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| Permissions | uint32 | in | Bitmap of permissions that the caller can inquire about. |
Call the GetEffectivePermission 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'GetEffectivePermission'
Arguments = @{ Permissions = 0 }
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) {
$result.ReturnValue
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Rename #
Class method that renames the logical file (or directory) specified in the object path.
uint32 Rename([in] string FileName);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| FileName | string | in | Fully qualified new name of the file (or directory). Example: c:\temp\newfile.txt |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the Rename 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Rename'
Arguments = @{ FileName = 'Example' }
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
TakeOwnerShip #
Class method that obtains ownership of the logical file specified in the object path.
uint32 TakeOwnerShip();Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the TakeOwnerShip 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'TakeOwnerShip'
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
TakeOwnerShipEx #
Class method that obtains ownership of the logical file specified in the object path.
uint32 TakeOwnerShipEx(
[out] string StopFileName,
[in] string StartFileName,
[in] boolean Recursive
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| StopFileName | string | out | Name of the file or directory where the TakeOwnerShipEx method failed. This parameter will be null if the method succeeds. |
| StartFileName | string | in | Names the child file or directory to use as a starting point for TakeOwnerShipEx.The *StartFileName* parameter is typically the *StopFileName* parameter specifying the file or directory at which an error occurred from the previous method call. If this parameter is NULL, the operation is performed on the file or directory specified in the ExecMethod call. |
| Recursive | boolean | in | If true, the change of ownership will be applied recursively to the files and directories within the directory specified by the CIM_LogicalFile instance. Note: For file instances, the *Recursive* parameter is ignored. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the TakeOwnerShipEx 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'TakeOwnerShipEx'
Arguments = @{
StartFileName = 'Example'
Recursive = $false
}
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
$result.StopFileName
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Uncompress #
Class method that uncompresses the logical file (or directory) specified in the object path.
uint32 Uncompress();Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the Uncompress 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'Uncompress'
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
UncompressEx #
Class method that uncompresses the logical file (or directory) specified in the object path.
uint32 UncompressEx(
[out] string StopFileName,
[in] string StartFileName,
[in] boolean Recursive
);Parameters
| Parameter | Type | Direction | Description |
|---|---|---|---|
| StopFileName | string | out | Name of the file or directory where the UncompressEx method failed. This parameter will be null if the method succeeds. |
| StartFileName | string | in | Names the child file or directory to use as a starting point for UncompressEx. The *StartFileName* parameter is typically the *StopFileName* parameter specifying the file or directory at which an error occurred from the previous method call. If this parameter is NULL, the operation is performed on the file or directory specified in the ExecMethod call. |
| Recursive | boolean | in | If true, the change of ownership will be applied recursively to the files and directories within the directory specified by the CIM_LogicalFile instance. Note: For file instances, the *Recursive* parameter is ignored. |
Return values
| Value | Label | Description |
|---|---|---|
| 0 | The request was successful. | |
| 2 | Access was denied. | |
| 8 | An unspecified failure occurred. | |
| 9 | The name specified was not valid. | |
| 10 | The object specified already exists. | |
| 11 | The file system is not NTFS. | |
| 12 | The platform is not Windows. | |
| 13 | The drive is not the same. | |
| 14 | The directory is not empty. | |
| 15 | There has been a sharing violation. | |
| 16 | The start file specified was not valid. | |
| 17 | A privilege required for the operation is not held. | |
| 21 | A parameter specified is not valid. |
Call the UncompressEx 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_PageFile -Filter "CSName = 'Example'"
$methodParameters = @{
InputObject = $instance
MethodName = 'UncompressEx'
Arguments = @{
StartFileName = 'Example'
Recursive = $false
}
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 = 'The request was successful'
2 = 'Access was denied'
8 = 'An unspecified failure occurred'
9 = 'The name specified was not valid'
10 = 'The object specified already exists'
11 = 'The file system is not NTFS'
12 = 'The platform is not Windows'
13 = 'The drive is not the same'
14 = 'The directory is not empty'
15 = 'There has been a sharing violation'
16 = 'The start file specified was not valid'
17 = 'A privilege required for the operation is not held'
21 = 'A parameter specified is not valid'
}
$returnValueName[[int]$result.ReturnValue]
$result.StopFileName
}This method can change the system. The -WhatIf parameter shows the operation without running it: remove it only after checking.
Remarks
The Win32_PageFile class is derived from CIM_Directory.
Inheritance
Superclass chain
Known subclasses
No known subclass.
Requirements
- Namespace
- root/cimv2
- Minimum client
- Windows Vista
- Minimum server
- Windows Server 2008
- Provider
- CIMWin32
- MOF file
- CIMWin32.mof
- DLL
- CIMWin32.dll
Class qualifiers
DEPRECATED Dynamic Provider("CIMWin32") Privileges("SeCreatePagefilePrivilege") UUID("{8502C4C6-5FBB-11D2-AAC1-006008C78BC7}") SupportsCreate CreateBy("PutInstance") SupportsDelete DeleteBy("DeleteInstance") SupportsUpdate AMENDMENT
Microsoft source
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.