Quick update, needed to add a bunch of new computer objects to a security group today. Figured I’d share this.

#Use one of the two below to get users.

#$arrObj = Get-ADComputer -Filter * -SearchBase "OU, DC, DC"

#$arrObj = Get-Content -Path <PathtoFile>

foreach($computer in $object)
{
    Get-ADComputer $computer | ForEach-Object {
        Add-ADGroupmember -identity 'Group Name' -members $_.SamAccountName
    }
}

Hey guys, another little update:

I’ve been working on utilizing the vSphere SDK as of late, but I’ve had little success in finding any useful guides. The VMWare site http://pubs.vmware.com/vsphere-60/index.jsp has some information that’s somewhat useful when attempting to learn how their SDK works, but I still didn’t get much out of it all. I googled around a bit to find bits and pieces and a lot of people expressed the same concern that I have – so I can at least relish the fact that I’m not alone in this thought. However, I want to try and figure it out to make my job a little easier and help develop some tools for the other individuals at our office. This will be a little mini-series of progressing through the vSphere SDK. I also wanted to provide some samples of a more recent build of the vSphere SDK, as a lot of other examples I’ve seen are relatively old and potentially out of date.

using System;
using System.Collections.Generic;
using VMware.Vim;

namespace VMTest
{
    class Program
    {
        // strings holding the basic data we'll need to connect
        private const string vURL = "https://iphere/sdk";
        private const string uName = "administrator@vsphere.local";
        private const string uPass = "password";
        
        static void Main()
        {
            Program p = new Program(); 
            Console.WriteLine("Starting the vSphere connection...");
            p.vSphere();
            Console.WriteLine("Program stopped!");
            Console.ReadKey();
        }
        
        public void vSphere()
        {
            //New VIServer connection
            VimClientImpl vClient = new VimClientImpl();
            //New connection to the vSphere Web Client (Over 443)
            ServiceContent sContent = vClient.Connect(vURL);
            //User credentials to utilize
            UserSession uSession = vClient.Login(uName, uPass);
            //Get the vms
            IList<EntityViewBase> vmList = vClient.FindEntityViews(typeof(VirtualMachine), null, null, null);
            //Power on the VMs
        
            foreach (VirtualMachine vm in vmList)
            {
                //VirtualMachine virt = (VirtualMachine)vm;
                Console.WriteLine("Powering on VM: " + vm.Name);
                ManagedObjectReference vmMor = vm.MoRef;
                vm.PowerOnVM(vm.MoRef);
            }
        
            //Log out of the vServer
            vClient.Logout();
        }
    }
}