powershell

Hey scripters! I recently had a task of migrating an entire virtual datacenter from one vCenter to another. It sounds like a pretty simple task, but manually recreating the cluster(s) could cause some human errors. I decided to write a script that would look at a specific vDatacenter and get all it’s clusters, then recreate that tree in the new vCenter. It’s pretty simple, really, it pulls all the clusters, then creates new clusters with the same attributes. When moving over the hosts, it first disconnects them from the original vCenter, then removes them from inventory.

I thought about disabling HA & DRS on the source vCenter cluster right before hand, but manually disconnecting & removing shouldn’t be an issue. If you add the host to the new vCenter without first removing from the old vCenter, that’s when you’ll get some HA weirdness because the old vCenter doesn’t know what just happened.

What does it do?

This post is long over due. I’ve been playing with Windows Server 2012 without the GUI (aka Core) for a while and one thing that irks me is that without the Graphical Management Tools, you’re really stuck using old school “net user” commands. Sure, you can use another GUI 2012 server’s Server Manager to connect and manage your core server, but what if you only have one core server you’re testing? Or, what if you simply want to do things the hard PowerShell way?

I had some ideas, since 2012 Core has the SConfig thing, I decided to do something similar and create a user-management script specifically for this scenario.

So what does it do? Some pretty basic tasks: create & delete users, create & delete groups, as well as edit users. Editing users includes changing the password, enable & disable, and adding & removing group membership. All done from a nice little PowerShell window!

I wrote this post a while back on how to use the API to convert VMs from thin to thick, which you could also go from thick to thin using it. I had written it because I was trying to use the inflate function, which isn’t allow against powered on VMs.

It was pointed out by a reader that I could have simply used Move-VM to accomplish the same task. This is great, shows how a second set of eyes and a different perspective can help you solve the problem. You could simply do

PowerShell

1

Move-VMvmservername-Datastoredatastorename-DiskStorageFormatthick

and it will move your VM to the specified datastore and convert to thick. You could use either thin or thick.

If you wanted to move every VM on a datastore, say Datastore1, to a new datastore, say Datastore2, and convert all of them to either thin or thick, you could do it like this:

You cannot specify the current datastore as the destination datastore, though. It will complete, but it will not convert your VM’s disk format, you have to actually Storage vMotion the VM to a different datastore. It basically validates the destination datastore is where it currently resides and exits without trying to convert your vmdk.

You could then take it a step farther and make a function that supports parameters, like if you wanted to move VMs on multiple datastores, or a given list of VMs to a specific datastore. For instance, you could create something like “convert-vms.ps1” and run it like this

Some of our older servers are running out of disk space on C:, so I needed to change the SCCM cache directory to D:. By default, this is where I wanted it anyway on our servers, leaving C: only for OS-related files. My OSD Task Sequences all have SMSCACHEDIR set to a folder on D in the client configuration step, but I noticed it wasn’t actually working. You know I had to find a way to fix that using powershell :D It actually ended up being really REALLY easy to do…

A few months ago, a reader by the name of Tolga ŞENTEKİN came across This Post looking for something to do a little more. Tolga was looking to script out DR for some VMs he has that use NetApp with & without RDMs. He & I spent about three weeks putting a script together to do the following:

Ever wonder how many users grant full control to Everyone on shares they created? This opens a huge risk, as any virus/worm can write itself to these shares, given the NTFS permissions allow them as well. At any rate, I don’t think it’s a good idea, so I scripted it out and found something like 470 shares where Everyone was granted FullControl access in my environment. OUCH!