<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ThepHuck</title>
	<atom:link href="http://thephuck.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://thephuck.com</link>
	<description>What ThepHuck is going on!</description>
	<lastBuildDate>Fri, 04 Nov 2011 15:52:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Error 25085 &#8211; Setup failed to register VMware Update Manager extension to VMware vCenter Server</title>
		<link>http://thephuck.com/virtualization/error-25085/</link>
		<comments>http://thephuck.com/virtualization/error-25085/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 15:30:29 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[4.1]]></category>
		<category><![CDATA[4.1u1]]></category>
		<category><![CDATA[Error 25085]]></category>
		<category><![CDATA[Update Manager]]></category>
		<category><![CDATA[vcenter]]></category>
		<category><![CDATA[VUM]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=280</guid>
		<description><![CDATA[I upgraded my vCenter to 4.1u1 while my VUM was still 4.0 (u2 iirc).  I decided to upgrade my VUM to match, and all was going well until I got this message: Error 25085 &#8211; Setup failed to register VMware &#8230; <a href="http://thephuck.com/virtualization/error-25085/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I upgraded my vCenter to 4.1u1 while my VUM was still 4.0 (u2 iirc).  I decided to upgrade my VUM to match, and all was going well until I got this message:</p>
<blockquote><p>Error 25085 &#8211; Setup failed to register VMware Update Manager extension to VMware vCenter Server</p></blockquote>
<p><span id="more-280"></span></p>
<p>I tried the following KB articles:</p>
<p><a href="http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&amp;cmd=displayKC&amp;externalId=1024795">http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&amp;cmd=displayKC&amp;externalId=1024795</a></p>
<p><a href="http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&amp;cmd=displayKC&amp;externalId=1003468">http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&amp;cmd=displayKC&amp;externalId=1003468</a></p>
<p><a href="http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&amp;cmd=displayKC&amp;externalId=1032709">http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&amp;cmd=displayKC&amp;externalId=1032709</a></p>
<p>Some of them didn&#8217;t quite apply because everything was working just fine before the upgrade, but doesn&#8217;t hurt to check.</p>
<p>I have two vCenters in linked mode, so I broke the link, still didn&#8217;t fix it.  During the setup, I would always specify the FQDN to my vCenter, as well as the VUM server to register in vCenter.  After I thought I&#8217;d tried everything (cleaning registry, checking the ADAM database, etc), I decided to try one last time before opening a case with VMware.</p>
<p>I stepped through everything just the same as before, but when I was at the step of specifying the VUM server to register in vCenter (IP or FQDN), I normally selected the hostname, so I decided to select the IP and everything installed and worked fine.</p>
<p>This may or may not work for any readers, but thought I&#8217;d share just in case it helps at least one other person.</p>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/virtualization/error-25085/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Function to export VMs with thin provisioned disks to CSV file</title>
		<link>http://thephuck.com/virtualization/function-to-export-vms-with-thin-provisioned-disks-to-csv-file/</link>
		<comments>http://thephuck.com/virtualization/function-to-export-vms-with-thin-provisioned-disks-to-csv-file/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 20:50:44 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[thin provisioned]]></category>
		<category><![CDATA[vmdk]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=270</guid>
		<description><![CDATA[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 &#038; name, Size in &#8230; <a href="http://thephuck.com/virtualization/function-to-export-vms-with-thin-provisioned-disks-to-csv-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>I have it pull the VM name, vmdk path &#038; name, Size in GB, and if it&#8217;s Thin Provisioned (Boolean, which should always be true).</p>
<p><span id="more-270"></span><br />
Just copy &#038; paste this into a .ps1 file and run it.  The initial instantiation of $vms takes a while, depending on the size of your environment, but the rest goes quickly.  Make sure you&#8217;re connected to a host or vcenter before you run it, or you won&#8217;t get anything.</p>
<pre><code>function find-thin{
    write-host -fore green `n "getting all VMs, this may take a while"

    $vms = get-vm |sort name |get-view

    Write-host -fore green `n "Starting Scan"

    $vmdks = @()

    foreach ($vm in $vms){
        foreach ($device in $vm.config.hardware.Device){
            if($device.GetType().Name -eq "VirtualDisk"){
                if($device.Backing.ThinProvisioned){
                    $info = "" | Select VM, File, SizeInGB, Thin
                    $info.VM = $vm.name
                    $info.File = $device.backing.filename
                    $info.SizeInGB = $device.capacityinkb/1048576
                    $info.thin = $device.Backing.ThinProvisioned
                    $vmdks += $info
                }
            }
        }
    }

    write-host -fore green `n "finished searching all VMs" `n

    $vmdks | export-csv d:\thindisk.csv
}

find-thin</code></pre>
<p>To change where the file is saved, simply change the path in line 27 to the destination of your choice.</p>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/virtualization/function-to-export-vms-with-thin-provisioned-disks-to-csv-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>function to list all VMs with Snapshots</title>
		<link>http://thephuck.com/virtualization/function-to-list-all-vms-with-snapshots/</link>
		<comments>http://thephuck.com/virtualization/function-to-list-all-vms-with-snapshots/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 20:43:32 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Find Snapshots]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[Snapshots]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=265</guid>
		<description><![CDATA[Using the PowerGUI, you can list all snapshots, but unfortunately, it doesn&#8217;t list the parent VM. I wrote a quick little function to search all VMs that have snapshots and list them. function get-snaps{ $vms = get-vm &#124; sort name &#8230; <a href="http://thephuck.com/virtualization/function-to-list-all-vms-with-snapshots/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Using the PowerGUI, you can list all snapshots, but unfortunately, it doesn&#8217;t list the parent VM.</p>
<p>I wrote a quick little function to search all VMs that have snapshots and list them.<br />
<span id="more-265"></span></p>
<pre><code>function get-snaps{
    $vms = get-vm | sort name
    $vmsnaps = @()
    foreach($vm in $vms){
    	$snap = Get-Snapshot $vm
    	if($snap){
		  $vmsnaps += $vm
		  write-host -fore green `n `t $vm
		  $snapshots = Get-Snapshot $vm
		  foreach ($snapshot in $snapshots){
			write-host "name: " $snapshot.name " size: " ($snapshot.sizemb/1024)
    		}
    	}
    }
}

get-snaps</code></pre>
<p>Just save that into a .ps1 file and run it.  Make sure you&#8217;re connected to a vCenter or it won&#8217;t work.</p>
<p>Expected output is like this:</p>
<pre><code>         Server1
name:  Description  size:  0.07853515625

         Server2
name:  Description    size:  3.79728515625

         Server3
name:  Consolidate Helper- 0  size:  1.6565625

         Server4
name:  Consolidate Helper- 0  size:  73.45369140625

         Server5
name:  Consolidate Helper- 0  size:  53.60998046875

         ARPDBW0025202
name:  Description    size:  0.01630859375</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/virtualization/function-to-list-all-vms-with-snapshots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List all shares with Everyone having FullControl access</title>
		<link>http://thephuck.com/server-management/list-all-shares-with-everyone-having-fullcontrol-access/</link>
		<comments>http://thephuck.com/server-management/list-all-shares-with-everyone-having-fullcontrol-access/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 21:09:31 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Server Management]]></category>
		<category><![CDATA[everyone fullcontrol]]></category>
		<category><![CDATA[full control]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[sharing]]></category>
		<category><![CDATA[windows file share]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=256</guid>
		<description><![CDATA[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 &#8230; <a href="http://thephuck.com/server-management/list-all-shares-with-everyone-having-fullcontrol-access/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>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&#8217;t think it&#8217;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!</p>
<p><span id="more-256"></span><br />
Keep in mind, this also shows printers.  I didn&#8217;t take the time to exclude them, so my script actually finds ~620 vulnerable shares.</p>
<p>For logging, just change <code>$script:logfile = "D:\everyoneshares.txt"</code> to whatever location you wish.</p>
<p>If you want to see more than just Full Control, change <code>if (($AccessMask -eq "FullControl") -AND ($myshare.ID -eq "Everyone")){$script:mylist += $myshare}</code> to match your desired output.</p>
<p>It also ignores any share that ends with a $ (administrative or hidden shares), change <code>$shares = gwmi Win32_LogicalShareSecuritySetting -co $comp -erroraction silentlycontinue |? {$_.Name -notlike "*$"} </code> to <code>$shares = gwmi Win32_LogicalShareSecuritySetting -co $comp -erroraction silentlycontinue</code> and it will look at ALL shares.</p>
<p>Now here&#8217;s the code:</p>
<pre><code>#OU Locations, make sure the index is in order, 1, 2, 3, etc.
#you cannot have 3 without 2, etc.
$ous = @{}
$ous[1] = 'LDAP://OU=Servers,DC=domain,DC=com'
$ous[2] = 'LDAP://OU=Another OU,DC=domain,DC=com'
$ous[3] = 'LDAP://OU=Domain Controllers,DC=domain,DC=com'

#set logfile directory
$script:logfile = "D:\everyoneshares.txt"

#This pulls all computer accounts from AD
function getresults($path,$cert) {
	$objDomain = New-Object System.DirectoryServices.DirectoryEntry
	$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
	$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry($path)
	$objSearcher.PageSize = 1000 # How many to retrieve at a time. Not output size.
	$objSearcher.Filter = $strFilter
	$objSearcher.PropertiesToLoad.Add("cn") >$null

	$colResults = $objSearcher.FindAll()
	foreach ($objResult in $colResults)
	{
	  $objItem = $objResult.Properties
	  $computer =  $objItem.cn[0]
	  $computer = $objItem.cn
	  $script:comps += $computer
  	}
}

#This runs the getresults function for each OU supplied above
$script:comps = @()

foreach ($ou in 1 .. $ous.Count) {
		if ($ous.$ou) {
			$strFilter = "(&#038;(objectClass=Computer))"
			getresults $ous.$ou
		}
}

$comps = $script:comps | Sort name
$script:mylist = @()
write-host `n
foreach ($comp in $comps) {#1

#here's where we actually pull each share from the current computer
    $shares = gwmi Win32_LogicalShareSecuritySetting -co $comp -erroraction silentlycontinue |? {$_.Name -notlike "*$"}
    if($shares){#2
    foreach ($share in $shares){#3
        $SecurityDescriptor = $Share.GetSecurityDescriptor()

		ForEach ($DACL in $SecurityDescriptor.Descriptor.DACL)
		{#4
			$myshare = "" | Select Server, Share, ID, AccessMask
            $myshare.Server = $comp
            $myshare.Share = $share.name
			$myshare.ID = $DACL.Trustee.Name
			Switch ($DACL.AccessMask)
			{#5
				2032127 {$AccessMask = "FullControl"}
				1179785 {$AccessMask = "Read"}
				1180063 {$AccessMask = "Read, Write"}
				1179817 {$AccessMask = "ReadAndExecute"}
				-1610612736 {$AccessMask = "ReadAndExecuteExtended"}
				1245631 {$AccessMask = "ReadAndExecute, Modify, Write"}
				1180095 {$AccessMask = "ReadAndExecute, Write"}
				268435456 {$AccessMask = "FullControl (Sub Only)"}
				default {$AccessMask = $DACL.AccessMask}
			}#5
			$myshare.AccessMask = $AccessMask

            if (($AccessMask -eq "FullControl") -AND ($myshare.ID -eq "Everyone")){$script:mylist += $myshare}

			Clear-Variable AccessMask -ErrorAction SilentlyContinue
    	}#4
      }#3
    }#2
}#1
$mylist | out-file $script:logfile
$count = $mylist.count
write-output `n "found $count shares where Everyone was given FullControl" | out-file $script:logfile -append
write-host `n</code></pre>
<p>I pieced this together from a few things I found on the net (querying AD and Shares), then combined the two and added logfile output.</p>
<p>I recommend using Start-Job for this, and get-job to see if it&#8217;s finished.  You don&#8217;t need to provide any input, and depending on your environment size, it could take quite some time.  Here&#8217;s the expected output:</p>
<pre><code>
Server                                       Share                                        ID                                           AccessMask
------                                       -----                                        --                                           ----------
Server-1                                     Share-1                                      Everyone                                     FullControl                                 

found 1 shares where Everyone was given FullControl
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/server-management/list-all-shares-with-everyone-having-fullcontrol-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add domain group to local administrator group in Windows using PowerShell</title>
		<link>http://thephuck.com/server-management/add-domain-group-to-local-administrator-group-in-windows-using-powershell/</link>
		<comments>http://thephuck.com/server-management/add-domain-group-to-local-administrator-group-in-windows-using-powershell/#comments</comments>
		<pubDate>Mon, 18 Jul 2011 19:31:52 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Server Management]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=251</guid>
		<description><![CDATA[I built 38 new servers and needed to add a domain group to the local administrator group of all of them. Instead of using computer management (compmgmt.msc) to connect to each one, or a GPO, I decided to use PowerShell, &#8230; <a href="http://thephuck.com/server-management/add-domain-group-to-local-administrator-group-in-windows-using-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I built 38 new servers and needed to add a domain group to the local administrator group of all of them.  Instead of using computer management (compmgmt.msc) to connect to each one, or a GPO, I decided to use PowerShell, and found it&#8217;s actually pretty simple to do.</p>
<p><span id="more-251"></span><br />
Here&#8217;s how we list local admins:<br />
First you have to get the group itself: <code>$group =[ADSI]"WinNT://$server/Administrators"</code> Then you have to get the members of that group: <code>$admins = @($group.psbase.Invoke("Members"))</code> Now to output those members: <code>$admins | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)</code></p>
<p>Adding is just as simple:<br />
Get the domain group: <code>$adgroup =[ADSI]"WinNT://domain/$admingroup"</code> Obviously you&#8217;ll have to change &#8216;domain&#8217; to the fqdn of your domain. Next we get the local group, same as we did above: <code>$localgroup =[ADSI]"WinNT://$server/Administrators"</code> Now we add the domain group to the local group: <code>$localGroup.PSBase.Invoke("Add",$adgroup.PSBase.Path)</code> You can run them separately, but I tied it all together to come up with my script so it shows me which server it&#8217;s working on and lists local admins when it&#8217;s done.</p>
<p>Servers and Admingroups are an array and can be specified like this: <code>Set-LocalAdmins.ps1 -servers ("host1","host2","host3") -admingroups ("group1","group2","group3")</code> or <code>Set-LocalAdmins.ps1 -servers host1 -admingroups group1</code></p>
<p>Here&#8217;s the script itself (don&#8217;t forget to change &#8216;domain&#8217; on line 10 to the fqdn of your):</p>
<pre><code>
param([string[]]$servers = $null, [string[]]$admingroups = $null)

function AddGroup(){
Foreach ($server in $servers){
    $ping = gwmi win32_pingstatus -filter "Address='$server'"
    #if it pings, check it
    if($ping.statuscode -eq 0){
        write-host -foregroundcolor "green" `n `t "Now working on $server"
        Foreach ($admingroup in $admingroups){
            $adgroup =[ADSI]"WinNT://domain/$admingroup"
            $localgroup =[ADSI]"WinNT://$server/Administrators"
            $localGroup.PSBase.Invoke("Add",$adgroup.PSBase.Path)
        }
        $localadmingroup =[ADSI]"WinNT://$server/Administrators"
        $admins = @($localadmingroup.psbase.Invoke("Members"))
        $admins | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
        }
    else{write-host -foregroundcolor Red `n`t "$server is not pingable" `n}
}
}

Function Usage(){
	Write-host -foregroundcolor green `n`t"This script is used to add domain groups to local admins."
	Write-host -foregroundcolor green `n`t"You can specify -servers and -admingroups as arrays:"
	write-host -foregroundcolor yellow `n`t`t"Set-LocalAdmins.ps1 -servers (`"host1`",`"host2`",`"host3`") -admingroups (`"group1`",`"group2`",`"group3`")"
	Write-host -foregroundcolor green `n`t"or specify each individually:"
	write-host -foregroundcolor yellow `n`t`t"Set-LocalAdmins.ps1 -servers host1 -admingroups group1" `n
}

if (($servers -eq $null) -or ($admingroups -eq $null)){
Usage
Break
}

AddGroup
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/server-management/add-domain-group-to-local-administrator-group-in-windows-using-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cisco Nexus 1000v</title>
		<link>http://thephuck.com/virtualization/cisco-nexus-1000v/</link>
		<comments>http://thephuck.com/virtualization/cisco-nexus-1000v/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 20:55:18 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[cisco nexus 1000v]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=247</guid>
		<description><![CDATA[I loath the Nexus 1000v. That is all&#8230;]]></description>
			<content:encoded><![CDATA[<p>I loath the Nexus 1000v.  That is all&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/virtualization/cisco-nexus-1000v/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create new role &amp; user on ESXi host via PowerCLI &amp; PowerShell</title>
		<link>http://thephuck.com/virtualization/create-new-role-user-on-esxi-host-via-powercli-powershell/</link>
		<comments>http://thephuck.com/virtualization/create-new-role-user-on-esxi-host-via-powercli-powershell/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 19:45:08 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[ESXi]]></category>
		<category><![CDATA[new-virole]]></category>
		<category><![CDATA[new-vmhostaccount]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[vmware roles]]></category>
		<category><![CDATA[vmware users]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=244</guid>
		<description><![CDATA[In this post I talked about automated deployment that launches the remote console for me. Since I had 24 hosts that need the user &#038; role, I created a script that does it for me. Nothing special, just something quick &#8230; <a href="http://thephuck.com/virtualization/create-new-role-user-on-esxi-host-via-powercli-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://thephuck.com/scripts/automated-deployment-script-builds-vm-registers-in-sccm/">this post</a> I talked about automated deployment that launches the remote console for me.  Since I had 24 hosts that need the user &#038; role, I created a script that does it for me.  Nothing special, just something quick that works&#8230;<br />
<span id="more-244"></span></p>
<p>You&#8217;ll need to change the password on line 11, as &#8216;changeme&#8217; does not meet default complexity requirements.</p>
<pre><code>param([string[]]$vmhosts = $null)

$esx_host_creds = $host.ui.PromptForCredential("ESX/ESXi Credentials Required", "Please enter credentials to log into the ESX/ESXi host.", "", "")

foreach ($vmhost in $vmhosts){

connect-viserver $vmhost -credential $esx_host_creds > $NULL 2>&#038;1

New-VIRole -name "Console-Only" -Privilege "Console interaction"

New-VMHostAccount -user -id console -password changeme -description "user acct for console only access"	

$AuthMgr = Get-View (Get-View ServiceInstance).Content.AuthorizationManager
$Entity = Get-Folder ha-folder-root | Get-View
$Perm = New-Object VMware.Vim.Permission
$Perm.entity = $Entity.MoRef
$Perm.group = $false
$Perm.principal = "console"
$Perm.propagate = $true
$Perm.roleId = ($AuthMgr.RoleList | where {$_.Name -eq "Console-Only"}).RoleId
$AuthMgr.SetEntityPermissions($Entity.MoRef,$Perm)

disconnect-viserver -confirm $false
}</code></pre>
<p>Usage is like this:
<pre><code>add-user.ps1 -vmhosts ("server1","server2","server3","server4","server5")</code></pre>
<p>It prompts you for a user/pass to connect to each ESXi host, so make sure you either have a working login with admin privs, or lockdown mode is NOT enabled and you have root pw.</p>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/virtualization/create-new-role-user-on-esxi-host-via-powercli-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated deployment script builds VM, registers in SCCM</title>
		<link>http://thephuck.com/scripts/automated-deployment-script-builds-vm-registers-in-sccm/</link>
		<comments>http://thephuck.com/scripts/automated-deployment-script-builds-vm-registers-in-sccm/#comments</comments>
		<pubDate>Fri, 27 May 2011 14:23:27 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[SCCM]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[automated deployment]]></category>
		<category><![CDATA[os deployment]]></category>
		<category><![CDATA[osd]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=230</guid>
		<description><![CDATA[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 &#8230; <a href="http://thephuck.com/scripts/automated-deployment-script-builds-vm-registers-in-sccm/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up to my last post about <a href="http://thephuck.com/scripts/powercli-vmware-sccm-sweetness-aka-automated-deployment/">fully automated deployment</a></p>
<p>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&#8217;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.<br />
<span id="more-230"></span></p>
<p>There are some variables you will have to set to make it work for you.  Our standard is to have two disks per VM, one for the OS, one for data.  I have the OS disk hard coded to 64GB, and the script prompts you for the data disk.  The OSID labels for the guest OS were taken from the API reference guide.</p>
<p>The SCCM portion was adapted from <a href="http://devinfra-us.blogspot.com/2008/04/sccm-and-powershell-part-2.html">Antoine Habert</a>, in combination with the <a href="http://thepowershellguy.com/blogs/posh/archive/2007/03/22/powershell-wmi-explorer-part-1.aspx">/\/\o\/\/ WMI Browser</a>.</p>
<p>This script also thin provisions both disks.  This can be changed in the createvm function.  Also, you will need PowerShell v2 and PowerCLI 4.1.1 to run this script.</p>
<pre><code>Add-PSSnapin VMware.* -ErrorAction SilentlyContinue

#instantiate script variables
set-variable -name clustername -scope script
set-variable -name vmhostname -scope script
set-variable -name networklabel -scope script
set-variable -name vcenter -scope script
set-variable -name vmname -scope script
set-variable -name vCPU -scope script
set-variable -name vRAM -scope script
set-variable -name vmdisk2 -scope script
set-variable -name store -scope script
set-variable -name desc -scope script
set-variable -name osid -scope script

#function to prompt for confirmation
function Confirm($strMessage)
{
write-host -foregroundcolor yellow `n $strMessage
$answer = $host.ui.rawui.readkey("NoEcho,IncludeKeyUp")
if ($answer.Character -ine "y")
    {
    write ""
    break
    }

write ""
}

#lists our supplied specs
function listspecs{
write-host -foregroundcolor green `n "These are the specs of the new server:"
write-host -foregroundcolor yellow `n`t "Environment:" $script:vcenter
write-host -foregroundcolor yellow `n`t "Server Name:" $script:vmname
write-host -foregroundcolor yellow `n`t "Number of CPUs:" $script:vCPU
write-host -foregroundcolor yellow `n`t "Amount of RAM:" $script:vRAM "GB"
write-host -foregroundcolor yellow `n`t "OS Disk: 64 GB" # 64GB is our standard
write-host -foregroundcolor yellow `n`t "Data Disk:" $script:vmdisk2 "GB"
write-host -foregroundcolor yellow `n`t "Cluster:" $script:clustername
write-host -foregroundcolor yellow `n`t "Network:" $script:networklabel
write-host -foregroundcolor yellow `n`t "Datastore:" $script:store
if($script:osid -eq "winLonghornGuest"){write-host -foregroundcolor yellow `n`t "Installing Windows 2008 x86"}
if($script:osid -eq "winLonghorn64Guest"){write-host -foregroundcolor yellow `n`t "Installing Windows 2008 x64"}
if($script:osid -eq "windows7Server64Guest"){write-host -foregroundcolor yellow `n`t "Installing Windows 2008 R2"}
if($script:osid -eq "winNetEnterpriseGuest"){write-host -foregroundcolor yellow `n`t "Installing Windows 2003 x86"}
if($script:osid -eq "winNetEnterprise64Guest"){write-host -foregroundcolor yellow `n`t "Installing Windows 2003 x64"}
Confirm("Press 'Y' to continue, or any other key to exit...")
}

#prompts for sizing specs of the VM
function getspecs{
    $script:vcenter = (read-host `n "vCenter server").tolower()
    $script:vmname = (read-host `n "Name of VM").toupper() #I like the name being in caps in vC
    $script:desc = (read-host `n "Enter a description for the notes (App, your name, etc)")
    [int]$script:vCPU = (read-host `n "Enter the number of CPUs")
    [int]$script:vram = (read-host `n "Enter the amount of RAM in GB")
    [int]$script:vmdisk2 = (read-host `n "Enter data disk size in GB")
    #need to populate OS ID with proper string to match the label
    write-host `n "Select OS Version"
    write-host `n "0 - Win2k8R2"
    write-host `n "1 - Win2k8x64"
    write-host `n "2 - Win2k8x86"
    write-host `n "3 - Win2k3x86"
    write-host `n "4 - Win2k3x64"
    $answer = read-host `n "Enter the number for the OS you're installing"
    if($answer -eq "0"){$script:osid = "windows7Server64Guest"}
    elseif($answer -eq "1"){$script:osid = "winLonghorn64Guest"}
    elseif($answer -eq "2"){$script:osid = "winLonghornGuest"}
    elseif($answer -eq "3"){$script:osid = "winNetEnterpriseGuest"}
    elseif($answer -eq "4"){$script:osid = "winNetEnterprise64Guest"}
}

#gets the desired cluster
#as well as a host in that cluster to gather network &#038; datastore info from
#then builds on that node of the cluster
#notice no sort order, so it won't pull the same host every time
Function ChooseCluster{
    $clslist = Get-cluster |sort name
    $i = 0
    write-host -foregroundcolor green `n "Choose a cluster"
    foreach ($cluster in $clslist){
    write-host -foregroundcolor green "$i - $cluster"
    $i++
    }
    $answer = read-host `n "Enter the number for the cluster you want"
    $script:clustername = $clslist[$answer]
    $vmhosts = get-vmhost -location $script:clustername
    $script:vmhostname = $vmhosts[0]
}

#lists datastores for one host of the cluster
#shows provisioned space as well as free space
#yellow if less than 150GB free
#red if less than 100GB free
Function ChooseDatastore{
    $datastores = Get-Datastore -vmhost $script:vmhostname |sort FreeSpaceMB -descending
    $i = 0
    write-host -foregroundcolor green `n "Choose a Datastore"
    foreach ($store in $datastores){
        $color = "green"
        if ($store.FreeSpaceMB -lt 153600){$color = "yellow"}
        if ($store.FreeSpaceMB -lt 102400){$color = "red"}
        $ds = Get-Datastore $store |sort name | Get-View
        $dsout = $ds | Select -ExpandProperty Summary | Select Name, @{N="Capacity GB"; E={[math]::round($_.Capacity/1073741824, 2)}}, @{N="Free GB"; E={[math]::round($_.FreeSpace/1073741824, 2)}}, @{N="Provisioned GB"; E={[math]::round(($_.Capacity - $_.FreeSpace + $_.Uncommitted)/1073741824, 2)}} |sort name
        write-host -foregroundcolor $color "$i - $dsout"
        $i++
    }
    $answer = read-host `n "Enter the number for the datastore you want"
    $script:store = $datastores[$answer]
}

#pulls available networks from the host in the cluster
Function ChooseNetwork{
    $networklist = Get-VirtualPortGroup -vmhost $script:vmhostname |sort name
    $i = 0
    write-host -foregroundcolor green `n "Choose a network"
    foreach ($network in $networklist){
    write-host -foregroundcolor green "$i - $network"
    $i++
    }
    $answer = read-host `n "Enter the number for the network you want"
    $script:networklabel = $networklist[$answer]
}

#connects to vcenter
function ConnectVCenter($script:vcenter){
    connect-viserver $script:vcenter > $NULL 2>&#038;1
}

#change -DiskMB to change disk 0:0 to the desired size
function CreateVM{
    #this creates the VM itself
    new-vm -vmhost $script:vmhostname -name $script:vmname -Datastore $script:store -DiskMB 65536 -diskstorageformat Thin -MemoryMB ($script:vRAM * 1024) -NumCpu $script:vcpu -CD -GuestID $script:osid -NetworkName $script:networklabel -Description $script:desc

    #this adds the data disk, since accepted size is kb, and prompt was gb, we have to convert it
    get-vm $script:vmname | New-HardDisk -capacitykb ($script:vmdisk2 * 1048576) -StorageFormat Thin
}

#disconnect from vc, null out variables just in case
function garbagecollection{
$script:clustername = $null
$script:vmhostname = $null
$script:networklabel = $null
$script:vcenter = $null
$script:vmname = $null
$script:vCPU = $null
$script:vRAM = $null
$script:vmdisk2 = $null
$script:store = $null
$script:desc = $null
$script:osid = $null

disconnect-viserver -confirm:$false
}

function AddToSCCM{

#sccm variables here
$SCCMServer = "" #enter the SCCM server name, used for WMI
$SCCMSite = "Site_" #example: Site_WSS, always 'Site_' and then 3 letter site code
$Colon = ":" #don't change this, makes life easier for the wmi path

#we need the mac to import computer into SCCM
$vnic =  Get-NetworkAdapter (get-vm $script:vmname)
$mac = $vnic.MacAddress

#specify collection based on OS ID
if($script:osid -eq "winLonghornGuest"){$targetColl = "2008 x86 Mandatory"}
elseif($script:osid -eq "winLonghorn64Guest"){$targetColl = "2008 x64 Mandatory"}
elseif($script:osid -eq "windows7Server64Guest"){$targetColl = "2008 R2 Mandatory"}
elseif($script:osid -eq "winNetEnterpriseGuest"){$targetColl = "2003 x86 Mandatory"}
elseif($script:osid -eq "winNetEnterprise64Guest"){$targetColl = "2003 x64 Mandatory"}

#create computer object
$Method = "ImportMachineEntry"
$Class = "SMS_Site"
$MC = [WmiClass]"\\$SCCMServer\ROOT\SMS\$SCCMSite$Colon$Class"
$InParams = $mc.psbase.GetMethodParameters($Method)
$InParams.MACAddress = $mac
$InParams.NetbiosName = $script:vmname
$InParams.OverwriteExistingRecord = $false
$inparams.PSBase.properties | select name,Value
$objCMComputer = $mc.PSBase.InvokeMethod($Method, $inParams, $Null)

#create direct rule for collection for target collection
$Class = "SMS_CollectionRuleDirect"
$objColRuledirect = [WmiClass]"\\$SCCMServer\ROOT\SMS\$SCCMSite$Colon$Class"
$objColRuleDirect.psbase.properties["ResourceClassName"].value = "SMS_R_System"
$objColRuleDirect.psbase.properties["ResourceID"].value = $objCMComputer.resourceID
$Collection = gwmi -computer $SCCMServer -namespace "root\sms\$SCCMSite" -class "SMS_Collection"
$svrCollection = $collection | where{$_.Name -eq "$targetColl"}

#add computer to target collection
$Class = "SMS_Collection"
$Method = "AddMembershipRule"
$CollectionID = $svrCollection.CollectionID
$filter="CollectionID = '$CollectionID'"
$MC = Get-WmiObject "SMS_Collection" -computer $SCCMServer -Namespace "ROOT\SMS\$SCCMSite" -filter $filter
$InParams = $mc.psbase.GetMethodParameters($Method)
$InParams.collectionRule = $objColRuledirect

$inparams.PSBase.properties | select name,Value
$AddComp = $mc.PSBase.InvokeMethod($Method, $inParams, $Null)

#update collection membership
start-sleep -s 15 #sleep for 15 seconds before requesting refresh of collection
$Method = "RequestRefresh"
$InParams = $mc.psbase.GetMethodParameters($Method)
$InParams.includesubcollections = $false
$inparams.PSBase.properties | select name,Value

$Refresh = $mc.PSBase.InvokeMethod($Method, $inParams, $Null)

}

function LaunchConsole{
$conuser = "conuser"
$conpw = "conpw"
$vm = get-vm $script:vmname
$currentvmhost = (get-vmhost -vm $vm).name
$vmxpath = $vm.ExtensionData.Summary.config.vmpathname
D:\"Program Files (x86)"\VMware\Infrastructure\"Virtual Infrastructure Client"\4.0\vmware-vmrc.exe -u $conuser -p $conpw -h $currentvmhost `"$vmxpath`"
}

##
#
# and now lets run all the functions
#
##
getspecs

ConnectVCenter($script:vcenter)

ChooseCluster

ChooseNetwork

ChooseDatastore

listspecs

CreateVM

start-sleep -s 15

AddToSCCM

start-sleep -s 15

start-vm $script:vmname > $NULL 2>&#038;1

LaunchConsole

garbagecollection</code></pre>
<p>**UPDATE 06/07/2011**<br />
I added one function to actually launch the remote console (vmware-vmrc.exe).  I hard-coded the path (line 222).  I have both 4.0 &#038; 4.1 installed, but used 4.0 for no particular reason, and also set the user &#038; pass as variables, or delete the -u &#038; -p from line 222 if you want to manually specify a user/pass each time.  This user will need to reside on the host specifically (I have a script that creates the Role, as well as the user, for this).  You could comment out the function call itself if you don&#8217;t want it (line 252).  I know the pw is there in clear text, but if created properly, it can only view the console.</p>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/scripts/automated-deployment-script-builds-vm-registers-in-sccm/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerCLI + VMware + SCCM = sweetness, aka automated deployment</title>
		<link>http://thephuck.com/scripts/powercli-vmware-sccm-sweetness-aka-automated-deployment/</link>
		<comments>http://thephuck.com/scripts/powercli-vmware-sccm-sweetness-aka-automated-deployment/#comments</comments>
		<pubDate>Thu, 26 May 2011 21:50:35 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[SCCM]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=225</guid>
		<description><![CDATA[So I&#8217;m creating a script that builds a VM for you, imports the NetBIOS name &#038; MAC address into SCCM, adds it to a specific collection, and then powers on the VM. If you have a mandatory OS Deployment for &#8230; <a href="http://thephuck.com/scripts/powercli-vmware-sccm-sweetness-aka-automated-deployment/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m creating a script that builds a VM for you, imports the NetBIOS name &#038; 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&#8217;t have to do anything but sit back and watch (given your Task Sequence is fully automated).</p>
<p>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&#8230;</p>
<p>I&#8217;m excited &#038; pleased that it&#8217;s actually working.  It&#8217;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.</p>
<p>Happy Scripting!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/scripts/powercli-vmware-sccm-sweetness-aka-automated-deployment/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Script I needed to get info for multiple VMs = Get-VMInfo.ps1</title>
		<link>http://thephuck.com/virtualization/quick-script-i-need-to-get-vm-info-for-multiple-vms-get-vminfo-ps1/</link>
		<comments>http://thephuck.com/virtualization/quick-script-i-need-to-get-vm-info-for-multiple-vms-get-vminfo-ps1/#comments</comments>
		<pubDate>Thu, 05 May 2011 16:26:39 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[ESXi]]></category>
		<category><![CDATA[get vm information]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[vcenter]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://thephuck.com/?p=214</guid>
		<description><![CDATA[I&#8217;ve recently had a ton of requests for information about specific VMs. They want to know how many disks they have, CPU count, how much RAM, and which environment the VM resides in. Instead of constantly searching vCenter, I wrote &#8230; <a href="http://thephuck.com/virtualization/quick-script-i-need-to-get-vm-info-for-multiple-vms-get-vminfo-ps1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently had a ton of requests for information about specific VMs.  They want to know how many disks they have, CPU count, how much RAM, and which environment the VM resides in.</p>
<p>Instead of constantly searching vCenter, I wrote this quickly during the meeting to query multiple servers.<br />
<span id="more-214"></span></p>
<pre><code>#only need one parameter here
param([string[]]$servers = "servers")

#add vmware snap-in
Add-PSSnapin VMware.* -erroraction silentlycontinue

#typical usage statements
function usage(){
    Write-host -foregroundcolor green `n`t"This script is used to retreive info for all servers provided."
    Write-host -foregroundcolor green `n`t"It pulls VM Host &#038; cluster info, OS provided in vCenter, number of CPUs &#038; RAM."
    Write-host -foregroundcolor green `n`t"Specify -servers in singular or in an array, like this:"
    write-host -foregroundcolor yellow `n`t`t"Get-VMInfo.ps1 -servers (`"server1`",`"server2`",`"server3`")"
    Write-host -foregroundcolor green `n`t"or"
    write-host -foregroundcolor yellow `n`t`t"Get-VMInfo.ps1 -servers server1" `n
    Write-host -foregroundcolor green `n`t"or"
    write-host -foregroundcolor yellow `n`t`t"Get-VMInfo.ps1 server1" `n
    }

#the main guts of the scripts
function GetInfo(){

foreach($server in $servers){
            #lets check and see if we're already connected somewhere
            if($global:DefaultVIServer){disconnect-viserver -confirm:$false}
            connect-viserver vcentername > $NULL 2>&#038;1
            $vm = get-vm $server -erroraction silentlycontinue
            if ($vm -ne $null){
                $vcls = get-cluster -vm $server
                $vdc = get-datacenter -vm $server
                write-host -foregroundcolor green `n "Server $server"
                write-host -foregroundcolor green `n "OS is" $vm.Guest.OSFullName
                write-host -foregroundcolor green `n "Running on host" $vm.vmhost "in the $vcls cluster in the $vdc Datacenter"
                if ($vm.memorymb -gt 1024){
                    $ram = [math]::round($vm.MemoryMB/1024, 0)
                    write-host -foregroundcolor green `n "It has" $VM.HardDisks.Count "virtual disks," $vm.NumCPU "CPUs, and $ram GB of RAM" `n
                    }
                else{write-host -foregroundcolor green `n "It has" $VM.HardDisks.Count "virtual disks," $vm.NumCPU "CPUs, and" $vm.memorymb "MB of RAM" `n}
                }
            elseif ($vm -eq $null){write-host -foregroundcolor red `n "Cannot find server in vCenter" `n;break}
            if($global:DefaultVIServer){disconnect-viserver -confirm:$false -erroraction silentlycontinue}
            }
    }

#making sure we have parameters
If($servers -eq "servers"){
    usage
    break
    }

getinfo</code></pre>
<p>I hard-coded my vcenter hostname in there, so you&#8217;ll need to change that line<br />
<code>connect-viserver vcentername > $NULL 2>&#038;1</code></p>
<p>Usage is like this:</p>
<pre><code>Get-VMInfo.ps1 servername</code></pre>
<p>or</p>
<pre><code>Get-VMInfo.ps1 ("server1","server2","server3")</code></pre>
<p>And expected output is like this:</p>
<pre><code>
Server Server1
OS is Red Hat Enterprise Linux 4 (32-bit)
Running on host esxihost1 in the cluster1 cluster in the vdatacentername Datacenter
It has 1 virtual disks, 1 CPUs, and 2 GB of RAM
</pre>
<p></code></p>
<p>Not real sophisticated, but works...</p>
]]></content:encoded>
			<wfw:commentRss>http://thephuck.com/virtualization/quick-script-i-need-to-get-vm-info-for-multiple-vms-get-vminfo-ps1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

