Posts tagged ‘powershell’

PowerCLI script to migrate clusters to new vCenter

Written April 30th, 2014 by
Categories: Scripts, Virtualization
4 comments

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?

Read the rest of this entry »

PowerShell User Management script for Windows Server 2012 Core

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!

Here’s a screenshot:
User Management Script Menu Read the rest of this entry »

Added VMware’s PowerCLI cmdlets to the powershell.php for WP-Syntax & GeSHi

Written February 14th, 2013 by
Categories: Scripts
No Comments »

I added a bunch of cmdlets for VMware’s PowerCLI to the cmdlets array in the powershell.php file.

So you don’t have to export and copy & paste them in to yours, I attached it to this post.

This is for the WP-Syntax plugin for WordPress that uses GeSHi to highlight certain things in the pre tag.

powershell.php

Just thought I’d share…

PowerCLI one liner to move all VMs on one datastore to another and convert to thick or thin

Written June 13th, 2012 by
Categories: Scripts, Virtualization
5 comments

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

Move-VM vmservername -Datastore datastorename -DiskStorageFormat thick

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:

Get-VM -Datastore Datastore1 | Move-VM -Datastore Datastore2 -DiskStorageFormat thick

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

convert-vms.ps1 -vms ("vm1",vm2","vm3","vm4") -destination datastore2 -thick

and it would move all four VMs to datastore2 and convert them to thick in the process. Or something like

convert-vms.ps1 -source ("datastore1","datastore2") -destination datastore3 -thin

That would move all VMs from datastores 1 & 2 and thin provision them on datastore3.

If anyone’s interested in the actual script/function, let me know and I can put one together fairly quickly.

Easy way to check if your PowerShell variable is an array or not

Written March 14th, 2012 by
Categories: Scripts
7 comments

I had a script that assumes something was an array, then failed when it wasn’t, so I needed a little checking:

$variable -is [system.array] will say True if it is an array, or False if not. You can also do $variable -isnot [system.array] and expect the exact opposite.

I chose to do this:

if($variable -isnot [system.array]){do some code expecting the $variable is not an array}

OR

if($variable -is [system.array]){do some other stuff with $variable[0] being an array}

Use Powershell to change SCCM cache directory & cache size

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…

Read the rest of this entry »

NetApp SnapMirror & RDMs – Automated failover

Written March 5th, 2012 by
Categories: Virtualization
1 Comment »

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:

  • Breaks snapmirror replication
  • Creates flexclones of the replicated volumes (given you’re licensed for it)
  • Map them to the esx hosts on the disaster recovery site
  • Adds and resignatures the LUNs and adds the VMs inside them to the inventory
  • After that, if you have RDM LUNs attached to the VMs, you first remove the old RDM Mappings from the VM and add the actual LUNs in the disaster site with the same LunID’s
  • If it’s all done you can start the Vm’s in the disaster site.

Tolga wrote the vast majority of the script, with me only contributing some of the datastore, LUN, & iSCSI stuff.

I uploaded it and have provided a link, since I didn’t want it to get sauteed up from a C&P.

Click HERE to download a copy of the script (right-click, save-as).  Obviously, you will need to edit & fine tune for your environment, but he & I wanted to share with the community.

Script to export VMs with thin provisioned disks to CSV file

Written September 12th, 2011 by
Categories: Scripts, Virtualization
3 comments

I wanted to know how many disks in our environment are thin provisioned, so I wrote a quick function to export that list to a CSV file.

I have it pull the VM name, vmdk path & name, Size in GB, and if it’s Thin Provisioned (Boolean, which should always be true).

Read the rest of this entry »

Function to list all VMs with Snapshots

Written September 12th, 2011 by
Categories: Scripts, Virtualization
No Comments »

Using the PowerGUI, you can list all snapshots, but unfortunately, it doesn’t list the parent VM.

I wrote a quick little function to search all VMs that have snapshots and list them.
Read the rest of this entry »

List all shares with Everyone having FullControl access

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!

Read the rest of this entry »

Designed by ThepHuck
Wordpress Themes
Scroll to Top