The main problem with your two lines of code was that you piped the output of the Get-VMResourceConfiguration cmdlet to a Format-List cmdlet. After you did this the properties of the object changed and you couldn't retrieve the NumCpuShares or the CpuSharesLevel properties anymore.
The object that is the result of the Get-VMResourceConfiguration cmdlet has the NumCpuShares and the CpuSharesLevel properties. So you could use this output directly as I did in my three lines of code.
You should use the Format-* cmdlets only if you want to show the output on the screen. That means that they always should be the last cmdlets in the pipeline.
Message was edited by: RvdNieuwendijk