Dsa.msc on Windows Server 2012 powershell commands

Install Active Directory Tools / dsa.msc on a domainmember:
Open a Powershell prompt with elevated privileges and enter the commands:

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell,RSAT-AD-Tools

Move vApp from one cluster to another in vCenter Server

To move a VMware  vApp from one cluster to another in vCenter Server (for example vCops):
  1. Click the UI and Analytics virtual machines to select them.
  2. Click the Summary tab. Take note of the network port group each virtual machine is using.
  3. Right-click the VMware vCenter Operations Manager vApp and click Power Off.
  4. When the UI and Analytics virtual machines power off, migrate them to another cluster.
  5. Right-click the VMware vCenter Operations Manager vApp and click New Virtual Machine.
Note: This virtual machine is temporary and created only so that the vApp can be exported. It is deleted when it is no longer required. You can perform the export with the UI or Analytics virtual machines but this is time consuming.

  1. Accept the defaults for creating the virtual machine with the exceptions:
    1. Use the same network port group as in Step 2.
    2. Select Thin Provision for the virtual disk type.
  2. Right-click the VMware vCenter Operations Manager vApp and click Edit Settings.
  3. On the Options tab, click Properties. Take note of the Timezone setting, the UI virtual machine IP Address, and the Analytics virtual machine IP Address. Click the Cancel button.
  4. Click to select the VMware vCenter Operations Manager vApp. Click File > Export > Export OVF Template.
  5. In the Directory field, enter a location to save the OVF file, then click OK.
  6. When the OVF export completes, right-click the VMware vCenter Operations Manager vApp and click Delete from disk.
  7. Click the required cluster to select it. Click File,then Deploy OVF Template.
  8. Accept the EULA when prompted.

    Note: The datastore location for the virtual machine files is not important as the UI and Analytics virtual machines are already stored on the appropriate datastores. This setting is only relevant to the temporary virtual machine created in Steps 5 and 6. This virtual machine will be deleted once recreated.

  9. Ensure that the Disk Format is set to Thin Provision.
  10. Under Properties, set the Timezone setting, the UI virtual machine IP Address and Analytics virtual machine IP address to the values in Step 8.
  11. On the Ready to Complete page, click Finish.
  12. When the vApp and temporary virtual machine are recreated, right-click the temporary virtual machine and click Delete From Disk.
  13. Migrate the UI and Analytics virtual machines to the VMware vCenter Operations Manager vApp.
  14. Right-click the VMware vCenter Operations Manager vApp and click Edit Settings.
  15. Click the Start Order tab. Ensure that the Analytics virtual machine is in Group 1 and the UI virtual machine is in Group 2.
  16. Select the Analytics virtual machine and set the options:
  • Startup Action, Operation: Power On
  • Startup sequence proceeds when: 1800 seconds have elapsed
  • Select: VMware Tools are ready
  • Shutdown Action, Operation: Guest Shutdown
  • Shutdown sequence proceeds when: 300 seconds have elapsed
  1. Repeat Step 21 with the UI virtual machine. When finished, click OK.

If a vApp is being moved to a new datacenter, you must configure an IP pool in the new datacenter to provide the networking environment for the vApp. For more information

Source: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2051492

 

Multiple Admin RDP Sessions Windows Server 2012 (R2)

Enable/Disable Multiple RDP Sessions in Windows 2012

By default, Windows 2012 servers allow a single Remote Desktop session. If only one session is available and you take over another person’s live session, you may choose to enable multiple RDP sessions

Enable Multiple RDP Sessions

  • Log into the server using Remote Desktop.
  • Open the start screen and type gpedit.msc
  • Go to Computer Configuration > Administrative Templates > Windows Components > Remote Desktop Services > Remote Desktop Session Host > Connections.
  • Set Restrict Remote Desktop Services user to a single Remote Desktop Services session to Disabled.
  • Double click Limit number of connections and set the RD Maximum Connections allowed to 999999.

Manage Windows server 2012 ABE powershell / script commands

Manage Access Based Enumeration from the cmdline or script:
Abecmd.exe is part of the Windows Server 2003 Access-Based Enumeration package.
With abecmd.exe it was possible to set ABE on or off from the commandline or scripts (Windows Server 2003 + Windows Server 2008).
As far as i know there is no package for Windows Server 2012. The only way to manipulate ABE without using te graphical interface is the below powershell command.

Set-SmbShare 2012srvtest$ -FolderEnumerationMode Accessbased -Confirm:$false
Set-SmbShare 2012srvtest$ -FolderEnumerationMode Unrestricted -Confirm:$false

If this information has helped you, please let me know. Leave a comment.

Powercli Connect-VIServer hide / mask password

If you need to connect to VC in Powercli  with other credentials then the logged on user you’re password is visible. On occasion you may have sensitive information being input that you don’t want pesky over-the-shoulder guests to see.
Anyone who takes over you’re RDP session can also read you’re password with “doskey” if the powercli shell is still open. 

Read-Host has a nice way of hiding the information with the -AsSecureString parameter.

In the IT Notes from the Powertoe – Tome Tanasovski i found a way to convert a Securestring to a string:
“-AsSecureString changes the output of the cmdlet from a String to a SecureString.  Generally this will be fine because you will probably be passing the captured output to another cmdlet that expects a SecureString, but this may not always be the case.   So how do you convert a SecureString to a String?  The answer is this Powerbit:”

$password=read-host -assecurestring
$decodedpassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))

I wrote this simple script to connect to VC without showing my password using -AsSecurestring:

clear
$vc = Read-Host “VirtualCenter Servername”
$dom = Read-Host “Domain”
$un = Read-Host “Username”
$password=read-host “Password:” -asSecurestring
$decodedpassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
Connect-VIServer –Server $vc -User $dom\$un -Password $decodedpassword

Powercli List all powered off VM’s

Get-VM | where {$_.powerstate -eq “PoweredOff”}

or PoweredOn VM’s:

Get-VM | where {$_.powerstate -eq “PoweredOn”}

Powercli Update VMWaretools without Reboot / input file


#

Function Check-ToolsStatus($vm){

$vmview = get-VM $vm | Get-View
$status = $vmview.Guest.ToolsStatus

if ($status -match “toolsOld”){
$vmTools = “Old”}
elseif($status -match “toolsNotRunning”){
$vmTools = “Not Running”}
else{
$vmTools = “Ok”}
return $vmTools
}

$input = Import-Csv C:\tmp\ps-scripts\input.csv
foreach($i in $input)
{
get-vm $i.Name.trim()
$vm = $i.Name.trim()

$vmToolsStatus = Check-ToolsStatus $vm

if($vmToolsStatus -eq “Old”){
Write-Host “The VMware Tools are old” -ForegroundColor Red

Get-VM $vm | Update-Tools –NoReboot }

# sleep 10

$vmToolsStatus = Check-ToolsStatus $vm

if($vmToolsStatus -eq “Ok”){
Write-Host “VMware Tools are installed on:” $vm -ForegroundColor Cyan}}

 

Powercli Update VMHardware + VMWaretools with input file


# Upgrade VMWare tools en Virtual Hardware (with auto reboot)
# Before running this script create c:\ps-scripts\input.csv and paste the Virtualmachinenames in it
# The first row must containe "Name" for example:
# Example inputfile:
# Name
# vm-01
# vm-02
# etc

# Start function definitions
Function PowerOn-VM($vm){

Start-VM -VM $vm -Confirm:$false -RunAsync | Out-Null

do {
$vmview = get-VM $vm | Get-View
$status = $vmview.Guest.ToolsStatus

Write-Host $vm is starting! -ForegroundColor Yellow
sleep 5

}until(($status -match "toolsOld") -or ($status -match "toolsOk"))

if ($status -match "Ok"){
$Startup = "Ok"}
elseif($status -match "toolsOld"){
$Startup = "ToolsOld"}
else{
$Startup = "Not Ready"}

return $Startup

}

Function PowerOff-VM{
param([string] $vm)

Shutdown-VMGuest -VM (Get-VM $vm) -Confirm:$false | Out-Null
Write-Host "Shutdown $vm"
do {
$status = (get-VM $vm).PowerState
}until($status -eq "PoweredOff")
return "OK"

}

Function Check-ToolsStatus($vm){

$vmview = get-VM $vm | Get-View
$status = $vmview.Guest.ToolsStatus

if ($status -match "toolsOld"){
$vmTools = "Old"}
elseif($status -match "toolsNotRunning"){
$vmTools = "Not Running"}
else{
$vmTools = "Ok"}
return $vmTools
}

Function Check-VMHardwareVersion($vm){
$vmView = get-VM $vm | Get-View
$vmVersion = $vmView.Config.Version
$v7 = "vmx-07"
$v9 = "vmx-09"

if ($vmVersion -eq $v7){
$vmHardware = "Old"}
elseif($vmVersion -eq $v9){
$vmHardware = "Ok"}
else{Write-Host "Error!!" -ForegroundColor Red
$vmHardware = "Error"}

return $vmHardware
}

Function Upgrade-VMHardware($vm){

$vmview = Get-VM $vm | Get-View
$vmVersion = $vmView.Config.Version
$v7 = "vmx-07"
$v9 = "vmx-09"

if ($vmVersion -eq $v7){
Write-Host "Version 7 detected" -ForegroundColor Red

# Update Hardware
Write-Host "Upgrading Hardware on" $vm -ForegroundColor Yellow
Get-View ($vmView.UpgradeVM_Task($v9)) | Out-Null
}
}

# End function definitions

# Action

$input = Import-Csv C:\ps-scripts\input.csv
foreach($i in $input)
{
get-vm $i.Name.trim()
$vm = $i.Name.trim()

# Check hardware status

$vmHardware = Check-VMHardwareVersion $vm
if ($vmHardware -eq "Ok"){
Write-Host $vm "is up to date" -ForegroundColor Green
}
else{Write-Host "Hardware is old" -ForegroundColor Red

# Check Toolstatus
$vmToolsStatus = Check-ToolsStatus $vm
if($vmToolsStatus -eq "Old"){
Write-Host "The VMware Tools are old on:" $vm -ForegroundColor Red
Sleep 20

Get-VMGuest $vm | Update-Tools
Sleep 120
Write-Host "VMware Tools are installed on:" $vm -ForegroundColor Cyan

$vmToolsStatus = Check-ToolsStatus $vm

if($vmToolsStatus -eq "Ok"){

$PowerOffVM = PowerOff-VM $vm
if($PowerOffVM -eq "OK"){
Write-Host $vm "is down" -ForegroundColor Yellow

Upgrade-VMHardware $vm
PowerOn-VM $vm
Write-Host $vm "is up to date" -ForegroundColor Green
}
}

}
else{
$PowerOffVM = PowerOff-VM $vm
if($PowerOffVM -eq "Ok"){
Upgrade-VMHardware $vm
PowerOn-VM $vm
Write-Host $vm "is up to date" -ForegroundColor Green

}
}
}
}
Sleep 40

Powercli show vmwaretools / virtual hardware status for all vm’s

Show VMWareTools and Virtual Hardware Status or export it to a csv:

# Define properties

New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty ‘Config.tools.ToolsVersion’ -Force
New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty ‘Guest.ToolsVersionStatus’ -Force
New-VIProperty -Name OSVersion -ObjectType VirtualMachine -ValueFromExtensionProperty ‘Guest.GuestFamily’ -Force

Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus,OSVersion | Export-Csv -NoTypeInformation -UseCulture -Path C:\tmp\\HW-ToolsStatus.csv

or by cluster:

Get-Cluster Clustername | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus,OSVersion | Export-Csv -NoTypeInformation -UseCulture -Path C:\tmp\\HW-ToolsStatus.csv

or by datacenter:

Get-Datacenter Datacentername | Get-VM | Select Name, Version, ToolsVersion, ToolsVersionStatus,OSVersion | Export-Csv -NoTypeInformation -UseCulture -Path C:\tmp\\HW-ToolsStatus.csv

 

vSphere syslogcollector change rotation size / interval

During the installation of the vSphere Syslog Collector you have to select the max size of the log files and when a rotation will happen. If you want to modify the collection behavior just edit vmconfig-syslog.xml:

Windows 2003 –> C:\Users\All Users\VMware\VMware Syslog Collector\vmconfig-syslog.xml
Windows 2008 –> C:\ProgramData\VMware\VMware Syslog Collector\vmconfig-syslog.xml

<defaultValues>
<port>514</port>
<protocol>TCP,UDP</protocol>
<maxSize>2</maxSize>
<rotate>8</rotate>
<sslPort>1514</sslPort>
</defaultValues>

Restart the vmware-syslog-collector service after modification.