Bulk Virtual Machines Deployment and Zero Clicks Part 2

Based on the CSV file used to create the VMs, re-use the CSV to control
Part 1 / Part 2

What else can I do now?

  • Delete Computer Objects from Active Directory
  • Bulk guest shutdown
  • Bulk power on virtual machines
  • Bulk power off virtual machines
  • Bulk Delete Virtual Machines from disk
  • Bulk change Computer Object OU

 

  • Delete Computer Objects from Active Directory

# Delete Computer Objects from Active Directory

$vmlist = Import-CSV .\Bulk_VMs_Deploy.csv

foreach ($item in $vmlist) {

$template = $item.template
$datastore = $item.datastore
$vmhost = $item.vmhost
$custspec = $item.custspec
$vmname = $item.vmname
$ipaddr = $item.ipaddress
$subnet = $item.subnet
$gateway = $item.gateway
$pdns = $item.pdns
$resourcepool = $item.resourcepool

Remove-ADComputer -Identity $vmname -Confirm:$false

}

 

  • Bulk guest shutdown

# Guest power down is a gracefull shutdown of the VMs
# VM requires VMware Tools to be installed on the VMs

Connect-VIServer vc6.test.domain

$vmlist = Import-CSV .\Bulk_VMs_Deploy.csv

foreach ($item in $vmlist) {

$template = $item.template
$datastore = $item.datastore
$vmhost = $item.vmhost
$custspec = $item.custspec
$vmname = $item.vmname
$ipaddr = $item.ipaddress
$subnet = $item.subnet
$gateway = $item.gateway
$pdns = $item.pdns
$resourcepool = $item.resourcepool

#Guest Shutdown VM
Shutdown-VMGuest $vmname
}
disconnect-VIServer vc6.test.domain -Confirm:$false

 

  • Bulk power on virtual machines

# Bulk power on virtual machines

Connect-VIServer vc6.test.domain

$vmlist = Import-CSV .\Bulk_VMs_Deploy.csv

foreach ($item in $vmlist) {

$template = $item.template
$datastore = $item.datastore
$vmhost = $item.vmhost
$custspec = $item.custspec
$vmname = $item.vmname
$ipaddr = $item.ipaddress
$subnet = $item.subnet
$gateway = $item.gateway
$pdns = $item.pdns
$resourcepool = $item.resourcepool

# POWER ON vms
Start-VM $vmname
}
disconnect-VIServer vc6.test.domain

 

  • Bulk power off virtual machines

# Bulk Power OFF VMs (Big Button OFF the VMs)
Connect-VIServer vc6.test.domain

$vmlist = Import-CSV .\Bulk_VMs_Deploy.csv

foreach ($item in $vmlist) {

$template = $item.template
$datastore = $item.datastore
$vmhost = $item.vmhost
$custspec = $item.custspec
$vmname = $item.vmname
$ipaddr = $item.ipaddress
$subnet = $item.subnet
$gateway = $item.gateway
$pdns = $item.pdns
$resourcepool = $item.resourcepool

#PowerOFF VM (Big Button OFF the VM)
Stop-VM $vmname -Confirm:$false

}

Disconnect-VIServer vc6.test.domain -Confirm:$false

 

  • Bulk Delete Virtual Machines from disk

# Delete Virtual Machines from disk
# VM should be already powered off

Connect-VIServer vc6.test.domain

$vmlist = Import-CSV .\Bulk_VMs_Deploy.csv

foreach ($item in $vmlist) {

$template = $item.template
$datastore = $item.datastore
$vmhost = $item.vmhost
$custspec = $item.custspec
$vmname = $item.vmname
$ipaddr = $item.ipaddress
$subnet = $item.subnet
$gateway = $item.gateway
$pdns = $item.pdns
$resourcepool = $item.resourcepool

Remove-VM -VM $vmname -DeleteFromDisk -Confirm:$false
}
disconnect-VIServer vc6.test.domain -Confirm:$false

 

  • Bulk change Computer Object OU#Move and AD Computer Object to a specific OU from a CSV file
    $vmlist = Import-CSV .\Bulk_VMs_Deploy.csvforeach ($item in $vmlist) {$template = $item.template
    $datastore = $item.datastore
    $vmhost = $item.vmhost
    $custspec = $item.custspec
    $vmname = $item.vmname
    $ipaddr = $item.ipaddress
    $subnet = $item.subnet
    $gateway = $item.gateway
    $pdns = $item.pdns
    $resourcepool = $item.resourcepoolGet-ADComputer $vmname|Move-ADObject -TargetPath “OU=VM,DC=TEST,DC=DOMAIN”
    }

 

Disclaimer Please take the code and evolve it into a different project? Credit / Tag me on your project Twitter #StephenHackers

Any use of this code is at your own risk. Remember bulk automation jobs require the right resources to be available.

Part 1 / Part 2

iPhone backups on Window 10

Is your iPhone backups filling your hard disk? Locate and relocate your back up files

Below is the locations of iPhone backups for each Windows OS.

Windows 8, Windows 10:

\Users\YOURUSERNAME\AppData\Roaming\Apple Computer\MobileSync\Backup

Windows 7 and Windows Vista:

C:\Users\<username>\AppData\Roaming\Apple Computer\MobileSync\Backup\

Windows XP:

C:\Documents and Settings\user\Application Data\Apple Computer\MobileSync\Backup”

Original detail can be found at igeeksblog.com

Differences between Roaming Profiles and ProfileimagePath

We have and RDS cluster everythings is working fine.

We use roaming profiles, redirection to a share is working as well.

When a user logs on to any RDS node we can see a user folder appear in E:\Users\ of the RDS Server.

When I checked the registry, and i can see 2 keys about profiles :
– you can see that the redirection is OK : Centralprofile (in my exemple \\Sharename\…)
– you can see a ProfileImagePath to E:\Users

So what is :
– A ProfileImagePath ?
– A CentralProfile ?

E:\Users\<username> is the local cache of the roaming profile.  I’ve never seen a setting to avoid caching of the profile on the local system entirely.

There is a group policy setting to automatically delete the cached copy upon user logout. It’s under Computer Configuation->Policies->Administrative Templates->System->UserProfiles->Delete cached copies of roaming profiles.

Plus side : This avoids disk space from caching the users profiles

Down side
It will probably increase the logon time as the full profile will have to copy every time.
When testing, this also cleared out the cache from a custom application which didnt right back to the roaming profile.

Group Policy –Add the Administrator security group to roaming users profiles

Tested on Windows 2008 R2

Create a GPO – “Add the Administrator security group to roaming users profiles”

Computer Configuration > Policies > Administrative Templates > System > User Profiles” and applied to Windows XP / 2003 or later.

Add the Administrator security group to roaming users profiles

This setting adds the administrator ACL to the users roaming profile path on the server when it is first created.

Administrator are able to view users profiles without the need to take ownership

Enable this option as soon as possible as this setting does NOT apply retrospectively to existing users profiles as it only applied the administrators group to the profile when the roaming profile when  it is created on the server for the first time.

Original detail posted by Alan Burchill

 

Check if an AD user has a roaming profile configured (PowerShell) – OneScript Team

Check if an AD user has a roaming profile configured (PowerShell)

This script can query specified active directory users whether or not a roaming profile was configured.

Scenarios

IT admins may care about which users has a roaming profile was configured. This script can help IT admins check whether or not a roaming profile was configured.

Script

Step 1: Run the script in the Windows PowerShell Console, type the command: Import-Module <Script Path> at the prompt.  For example, type Import-Module C:\Script\CheckIfProfileExists.psm1

This is shown in the following figure.

Step 2: Type the command Get-Help Get-OSCADUserRoamingProfile -Full to display the entire help file for this function, such as the syntax, parameters, or examples.

OneScript Team

Temp Profile issue 2008 R2 RDS using roaming profiles

Issue
Some of our users keep getting logged on with a temporary profile.

Scenario
We have an RDS cluster using Window 2008 R2 x64 and users are setup with roaming profiles.

Profiles going to \\server\users\%username% Intermittently the folder is being created in the profile share but the folder is empty.

Permissions checked ok Shares checked ok

Cause
Possibly caused by a server crash corrupting the profiles instead of a natural logoff allowing the profile to write back.

Solution
Browse the registry on your terminal server under :  LM\software\Microsoft\Windows NT\CurrentVerision\ProfileList

Look for any keys under ProfileList with an extension “.bat”
Select key and click delete (export or backup any keys before making changes or deletions first.)

Solution found here : http://www.brianmadden.com/

 

SQL 2012 install on Server 2012R2 “Error while enabling Windows feature NetFx3”

Problem… “Error while enabling Windows feature NetFx3″

We wanted to install APP-V 5.x on server 2008 running SQL 2008. At the very start this was a problem. Error you require a later version of the OS etc.

So we deployed 2012 R2, and then started to install SQL 2012….. error during install …

“Microsoft SQL Server 2012 Release Candidate 0 Setup
The following error has occurred:
Error while enabling Windows feature: NetFx3, Error Code: -2146498298, Please try enabling
Windows feature: NetFx3 from Windows management tools and then run setup again.”

Cancel install

We then tried to enable .NET Framework 3.5 on Windows Server 8 using the “Add Roles and Features Wizard” of Windows Serve 2012.

“Failed”

Next attempt.

Load 2012 disk & connect the server to the internet

Launch CMD as administrator

dism /online /enable-feature /all /featurename:NetFx3 /source:d:\sources\sxs

The operation finished successfully from the command prompt.

We then were able to install SQL Server 2012 successfully.

 

We also found this link to be useful for screen shots

 

Change user command to switch a Terminal Services server to Install mode.

KB 320185

How to put a Terminal Services server in Install mode.

You will need to switch to install mode, to install or remove programs on a terminal server.

The method I use the most is :
Open command prompt as administrator

Type:         change user /install
This will change the server to install mode.

Now your ready to install applications.

Switch Terminal Services to Execute Mode, when you are finished adding or removing programs.

Open command prompt as administrator

Type:         change user /execute

Users can now log in and start using the new applications