一些单行灵感来自谁跟随我在twitter上的人,首先杰森博凯是工作在一个脚本来复位CPU和内存限制为“无限的vCenter中的所有虚拟机,我跟他开玩笑说,这是一个单行,首先,我们可以设置以下的内存限制:

Get-VM | Get-VMResourceConfiguration | Where-Object {$_.MemLimitMB -ne-1} | Set-VMResourceConfiguration-MemLimitMB$null

The –1 equates to an “Unlimited” setting.  This doesn’t address the CPU limits, this can be done using the following:

Get-VM | Get-VMResourceConfiguration | Where-Object {$_.CpuLimitMhz -ne-1} | Set-VMResourceConfiguration-CPULimitMhz$null

But thats two lines, whilst we can do it on one line we cant easily add some checking to see if they are already set so the following one-liner will set them even if they are already set, this will take a bit longer than is ideal but it gets the job done and I can still hold my head up high knowing I can do it in one line

Get-VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration-MemLimitMB$null-CpuLimitMhz$null

The next one-liner was inspired by Mark Stang who asked:

This is something that i too wish there was an easy way to do, if you could somehow pass the original object down the pipeline it would be so easy to do this and more powerfull things, if there is a way and you know then please tell me !

In any case, after a bit of messing I was able to get this down to one-line and still give the desired result:

Get-vm | SelectName, @{N=Network;E={$_ | Get-networkAdapter | ? {$_.macaddress -eq00:50:56:A1:50:43}}} |Where {$_.Network-ne“”}

This gives both the name of the VM and the network adapter which has the Mac address we searched for.

I just also wanted to add that not everything in Powershell is a one-liner, I only do these to show how powerfull PowerShell can be, these are sometimes harder for beginners to understand but heck they are fun, kinda the PowerShell geeks version of Sudoku.
51cto.com/a/luyoujiaohuan/index.html
http://www.net527.com
Linux 系统