Posts tagged ‘powershell’

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

Written March 14th, 2012 by
Categories: Scripts
No 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}
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.

Function to export VMs with thin provisioned disks to CSV file

Written September 12th, 2011 by
Categories: Scripts, Virtualization
No 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 »

Automated deployment script builds VM, registers in SCCM

This is a follow-up to my last post about fully automated deployment

Below is the script. After it pulls the information from you, it creates the VM, adds the second disk, sleeps for 15 seconds, pulls the MAC from the new VM, creates the computer object in SCCM, adds it to the collection, sleeps for 15 seconds, refreshes the collection, sleeps for 15 seconds, then powers on the VM. If you’ve got a mandatory OSD advertised to the collection specified, and the OSD is fully automated, it will lay down the OS and the computername will be the name you provided to the script.
Read the rest of this entry »

PowerCLI + VMware + SCCM = sweetness, aka automated deployment

Written May 26th, 2011 by
Categories: Scripts
3 comments

So I’m creating a script that builds a VM for you, imports the NetBIOS name & MAC address into SCCM, adds it to a specific collection, and then powers on the VM. If you have a mandatory OS Deployment for that collection, you don’t have to do anything but sit back and watch (given your Task Sequence is fully automated).

It prompts you for vCenter name, VM name, cpu, ram, description, disk size, queries vcenter for clusters, networks, datastores (sorted by free space), and verifies with you before building…

I’m excited & pleased that it’s actually working. It’s currently proprietary to my work environment, but I will try to strip all that out and let you change what needs to be changed to use it where you like.

Happy Scripting!!!

PowerShell multithreaded script to recursively search for file types, shows count and total size

Written February 10th, 2011 by
Categories: Scripts
No Comments »

I recently had a requirement to build a script that listed all PST files on some of our DFS folders. I know there are a bunch of ways to get this done, but I wanted to build my own way. Since we needed to search roughly 20 directories, I decided to play with the Start-Job cmdlet so I could have one script to spawn multiple worker processes. At first, it was tricky (since I had never even messed with it), but anyone can easily pick it up.

Read the rest of this entry »

Script to pull host UUID for VMware PowerCLI

Written February 2nd, 2011 by
Categories: Scripts
8 comments

A reader on a previous post asked about pulling host UUIDs, so I wipped together this script.

Usage is like this:
Get-VMHostUUID.ps1 -vmhosts ("host1","host2","host3")or
Get-VMHostUUID.ps1 -vc vcenterserver -container cluster1/folder/dc/etc
Read the rest of this entry »

Designed by ThepHuck
Wordpress Themes
Scroll to Top