[SOLVED] Powershell's cmdlet "Get-Partition" started to give error messages again

etord72

Reputable
May 25, 2019
10
0
4,510
0
Hi,
I've been using the following command line in a macro:
PS C:\directories> Get-Partition -DriveLetter W | Set-Partition -NewDriveLetter G

It worked just fine for a while, then started to give this error message:

Set-Partition : The operation failed with return code 42012
Activity ID: {ad7ee5ca-3f2f-49b8-9abf-2153ce9af4d9}
At line:1 char:32
  • Get-Partition -DriveLetter W | Set-Partition -NewDriveLetter G
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (StorageWMI:ROOT/Microsoft/..._StorageCmdlets) [Set-Partition], CimException
+ FullyQualifiedErrorId : StorageWMI 42012,Set-Partition

I haven't done anything unusual to the system, which runs on Windows 10.
Previously, though, I had a similar issue, with the powershell giving errors after that same command line, out of the blue. But I solved that problem thanks to some code suggested by an advanced user, which made it work without issues until now.
I'm quoting below the thread with my previous issue and its working solution:

Hi,
for years I've been using the PowerShell's commands GET-PARTITION and SET-PARTITION to change drive letters using a macro, without any issue.Recently, PowerShell started giving the "INVALID PROPERTY" error message (see below).
I can't tell when this started to happen, but I recently ran some optimizers, like "Windows repair" by tweaking.com, which my have tampered with the system and the environment variables.
Can someone please hint me on a possible cause or where to start looking for it?
Please, note that I'd prefer to keep using this powershell command, so i.e. diskpart wouldn't be feasible alternative.
I'm using Windows 10 Pro, regularly updated.
Thanks!

PS C:\> Get-Partition
get-partition : Invalid property
At line:1 char:1
  • get-partition
  • ~~~~~~~~~~~~~
  • CategoryInfo : MetadataError: (MSFT_Partition:ROOT/Microsoft/.../MSFT_Partition) [Get-Partition], CimException
  • FullyQualifiedErrorId : HRESULT 0x80041031,Get-Partition
try this in cmd:
Code:
sc config winmgmt start= disabled
net stop winmgmt
Winmgmt /salvagerepository %windir%\System32\wbem
Winmgmt /resetrepository %windir%\
sc config winmgmt start= auto

Thanks!
 
I've been using the following command line in a macro:
PS C:\directories> Get-Partition -DriveLetter W | Set-Partition -NewDriveLetter G
It worked just fine for a while, then started to give this error message:
Set-Partition : The operation failed with return code 42012
You have to run the command from elevated Power Shell.
If you run it from regular Power Shell, you get error 42012.
 
Reactions: rgd1101

etord72

Reputable
May 25, 2019
10
0
4,510
0
I've been using the following command line in a macro:
PS C:\directories> Get-Partition -DriveLetter W | Set-Partition -NewDriveLetter G
It worked just fine for a while, then started to give this error message:
Set-Partition : The operation failed with return code 42012
You have to run the command from elevated Power Shell.
If you run it from regular Power Shell, you get error 42012.
 
Reactions: rgd1101

etord72

Reputable
May 25, 2019
10
0
4,510
0
You have to run the command from elevated Power Shell.
If you run it from regular Power Shell, you get error 42012.
Thanks! That's correct.
What really puzzles me, now, is why it worked before, without running as an administrator, but that I'll find out.
Thanks a lot, SkyNetRising!
 

etord72

Reputable
May 25, 2019
10
0
4,510
0
You probably just didn't notice, it was running in administrator mode before.
It should not have worked without it.
That's right, it was actually the macro that executed the commands that wasn't set to run in admin mode, while it probably was before. Then I had to re-install it and I forgot to set it.
Thanks to all for the help!
 

ASK THE COMMUNITY

TRENDING THREADS