11 August 2015

F5 GTM Zone Transfer Files

If you need to manually export a zone for some or other purpose you can simply grab the files form the GTM directly.


The zone files are located in

/var/named/config/namedb

The files are named as follows

db.external.domain.domain.

You can check the content of the file with nano or vi or you can SCP the file locally and save it there.


20 July 2015

Mac OSX Auto proxy configuration from the shell

If you are usinf a Mac and you are jumping between multiple proxy these commands may come in handy to switch various proxy setting on and off.

You can of course go in via the Setting GUI, but trust me, after a while it gets a bit old.

The two setting you will most likely want to turn on and off are


  • Auto Proxy Discovery
  • AutoMatic Proxy Configuration


You may also want to explicitly define the two below but auto is where you should be as ti configure a lot of stuff for you including exclusions.


  • Web (HTTP)
  • Secure Web Proxy (HTTPS)



Before you can specify any commands you need to know which network interface or network service you need to use.  To get the list run


sudo networksetup -listallnetworkservices

AutoProxy Discovery 

sudo networksetup -setproxyautodiscovery "Thunderbolt Ethernet" on

or

sudo networksetup -setproxyautodiscovery "Thunderbolt Ethernet" off


Automatic Proxy Configuration

Enable it

sudo networksetup -setautoproxystate "Thunderbolt Ethernet" on

Disable it

sudo networksetup -setautoproxystate "Thunderbolt Ethernet" on


Configure the URL

sudo networksetup -setautoproxyurl "Thunderbolt Ethernet" "http://utm02.domain.co.za:8080/wpad.dat"

Blank it 

sudo networksetup -setautoproxyurl "Thunderbolt Ethernet" " "


To manually specify the proxy

sudo networksetup -setwebproxy "Thunderbolt Ethernet" "webproxy" 8080 

with authentication

sudo networksetup -setwebproxy "Thunderbolt Ethernet" "webproxy" 8080 on username password




set the bypass or exclusions


sudo networksetup -setproxybypassdomains  "Thunderbolt Ethernet" "*.mydomain" "*.otherdomain" "10.0.0.0/8"


25 May 2015

Retrive Hyper-V host details from within the VM

Normally it is not hard to keep track of where your VMs are running.   After all there are numerous consoles and tools to use during the various stages or environments a VM can be in.

If however you find yourself with a VM that is on the network and you cannot track down the host that owns it you can get some of the host information from the VM providing the guest services are installed and running

The Registry key that maintains this information in the VM is

HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters

"HostName"="Hypervman0"
"HostingSystemEditionId"=dword:00000007
"HostingSystemOsMajor"=dword:00000006
"HostingSystemOsMinor"=dword:00000003
"HostingSystemProcessorArchitecture"=dword:00000009
"HostingSystemSpMajor"=dword:00000000
"HostingSystemSpMinor"=dword:00000000
"PhysicalHostName"="HYPERVMAN0"
"PhysicalHostNameFullyQualified"="Hypervman0.domain.co.za"
"VirtualMachineId"="CA0BDECF-2DDB-4388-A6B8-BACED5283354"
"VirtualMachineName"="VMname"

You can retrieve this info from  the registry or run the following PowerShell just to return the name

(Get-ItemProperty –path "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").PhysicalHostName

09 April 2015

Find duplicate VMs in your SCVMM environement

Sometimes there is a reason for legitimately having duplicate VM names that would not cause a problem at all.  If you have a replicated VM you would have two, one on the other off.

You could also have a VM stored in the library that is the same name as a server that is currently deployed.

Then there are the duplicate VMs that your really want to find and get rid of.  These can be cause by a number of factors, most of them human.

To track down duplicates use the following

Get-SCVirtualMachine | group -Property name |? {$_.Count -gt 1} | % {$_.Group} | Select-Object Name,virtualmachinestate,IsPrimaryVM, IsRecoveryVM,ID  ,hostname,HostGrouppath  | Format-Table -AutoSize

It will give you an output similar to this



The green machines are an actual replicated pair and is not a problem.
The amber machines is a duplicate we would like to get rid of.

The command will also give you the unique ID.  You can remove the unwanted duplicate using the following

Get-SCVirtualMachine -ID "****copyfromoutput****" | Remove-SCVirtualMachine -Force

26 March 2015

VMM Powershell Assign Logical Network to VMhost adapters

One step that cannot easily be automated to multiple hosts is assigning the logical network a VM host has been grated access to to a physical adapter on the host.  The following PowerShell allows you to set this.



$logicalNetwork = Get-SCLogicalNetwork -Name "Virtual Machine VLANS"
$vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -VMHost hyperv02 | where {$_.ConnectionName -eq "VM Traffic"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork

You can also string this together for multiple network on host group members

You can get the group names with

Get-VMHostGroup | select path | Sort-Object path

And the logical network names with

get-sclogicalnetwork | select name | Sort-Object name

This will give you what you need to complete the $netlist and $members sections


$netlist = "Hyper-V Management","Virtual Machine VLANS", "Core Infrastructure VLANS","F5 VLANS"

foreach ($net in $netlist)
{
$logicalNetwork = Get-SCLogicalNetwork -Name $net
    $members = Get-VMHost | where {$_.VMHostGroup -like "All Hosts\DC2 Data Center\Best - HA EMC"}
    foreach ($M IN $members)
    {
    $vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -VMHost $m.Name | where {$_.ConnectionName -eq "VM Traffic"
    Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -AddOrSetLogicalNetwork $logicalNetwork
    }

}


19 March 2015

SCVMM - Change the display name of a VmHoSt to fix capitalisation

A Personal per peeve is when you are looking at your beautiful VMM console and all of your hosts line up perfectly except one, someone added it with the host name specified in the wrong CASE.  You cannot fix this be renaming the host or anything else you might try - yes I tried a few ways.

The only way to fix it is to edit the database directly

Here is my crude but effective query


update dbo.tbl_ADHC_Host
set ComputerName = REPLACE(ComputerName, 'hyperv10.ww.co.za', 'HYPERV10.ww.co.za')
where ComputerName = 'hyperv10.ww.co.za'

select * from dbo.tbl_ADHC_Host

Remove a VMhost from SCVMM when all else fails

Occasionally you will get stuck with an VMhost that you cannot remove from VMM

Your first call would be do run power shell and attempt

Remove-SCVMHost -VMHost stuckHVhost -force

If this also fails you will have to go edit the database directly.  Make sure you have a backup of your database in case something goes horribly pear-shape.

Before you start make sure you get the host ID by running

get-scvmhost -ComputerName stuckHVhost | select id, name

Stop the VMM service and open up your SQL management studio and start a new query on the VMM database

All you need to set is @deletehostid ( second line)

DECLARE @DeleteHostId GUID;
SET @DeleteHostId = ''

PRINT N'Deleting host with GUID ' + RTRIM(CAST(@DeleteHostID AS nvarchar(50)))

PRINT N'Getting host cluster GUID'

DECLARE @HostClusterID GUID;
SET @HostClusterID =
(
SELECT HostClusterID FROM [dbo].[tbl_ADHC_Host]
WHERE HostID = @DeleteHostId
)

IF (@HostClusterID IS NOT NULL)
PRINT N'Retreived host cluster GUID ' + RTRIM(CAST(@HostClusterID AS nvarchar(50)))
ELSE
PRINT N'This host does not belong to a cluster'

PRINT N'Deleteing physical objects'

DELETE FROM [dbo].[tbl_WLC_PhysicalObject]
WHERE HostId = @DeleteHostId

PRINT N'Deleteing virtual objects'

DELETE FROM [dbo].[tbl_WLC_VObject]
WHERE HostId = @DeleteHostId

PRINT N'Prepairing to delete host network adapters'

DECLARE @HostNetworkAdapterCursor CURSOR;
DECLARE @HostNetworkAdapterID GUID;
SET @HostNetworkAdapterCursor = CURSOR FOR
(SELECT NetworkAdapterID FROM [dbo].[tbl_ADHC_HostNetworkAdapter])

OPEN @HostNetworkAdapterCursor

FETCH NEXT FROM @HostNetworkAdapterCursor INTO @HostNetworkAdapterID

WHILE (@@FETCH_STATUS = 0)
BEGIN
PRINT N'Prepairing to delete host network adapter with GUID ' + RTRIM(CAST(@HostNetworkAdapterID AS nvarchar(50)))

PRINT N'Deleting logical network mapping for host network adapter with GUID ' + RTRIM(CAST(@HostNetworkAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_NetMan_HostNetworkAdapterToLogicalNetwork]
WHERE HostNetworkAdapterID = @HostNetworkAdapterID

PRINT N'Deleting IP subnet VLAN mapping for host network adapter with GUID ' + RTRIM(CAST(@HostNetworkAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_NetMan_HostNetworkAdapterToIPSubnetVLan]
WHERE HostNetworkAdapterID = @HostNetworkAdapterID

FETCH NEXT FROM @HostNetworkAdapterCursor INTO @HostNetworkAdapterID
END

CLOSE @HostNetworkAdapterCursor
DEALLOCATE @HostNetworkAdapterCursor

PRINT N'Completing host network adapters deletion'

DELETE FROM [dbo].[tbl_ADHC_HostNetworkAdapter]
WHERE HostID = @DeleteHostId

PRINT N'Deleting virtual networks'

DELETE FROM [dbo].[tbl_ADHC_VirtualNetwork]
WHERE HostID = @DeleteHostId

PRINT N'Deleting virtual switch extensions'

DELETE FROM [dbo].[tbl_NetMan_InstalledVirtualSwitchExtension]
WHERE HostID = @DeleteHostId

PRINT N'Deleting host volumes'

DELETE FROM [dbo].[tbl_ADHC_HostVolume]
WHERE HostID = @DeleteHostId

PRINT N'Deleting pass through disks'

DELETE FROM [dbo].[tbl_WLC_VDrive]
WHERE HostDiskId IN (SELECT DiskID FROM [dbo].[tbl_ADHC_HostDisk] WHERE HostID IN (SELECT HostID FROM [dbo].[tbl_ADHC_Host] WHERE HostID = @DeleteHostId))

PRINT N'Deleting host disks'

DELETE FROM [dbo].[tbl_ADHC_HostDisk]
WHERE HostID = @DeleteHostId

PRINT N'Prepairing to delete host bus adapters'

DECLARE @HostBusAdapterCursor CURSOR;
DECLARE @HostBusAdapterID GUID;
SET @HostBusAdapterCursor = CURSOR FOR
(SELECT HbaID FROM [dbo].[tbl_ADHC_HostBusAdapter])

OPEN @HostBusAdapterCursor

FETCH NEXT FROM @HostBusAdapterCursor INTO @HostBusAdapterID

WHILE (@@FETCH_STATUS = 0)
BEGIN

PRINT N'Prepairing to delete host bus adapter with GUID ' + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

PRINT N'Deleting fiber port mapping for host bus adapter with GUID ' + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DECLARE @FiberPortID GUID;
SET @FiberPortID =
(
SELECT PortID FROM [dbo].[tbl_ADHC_FCHbaToFibrePortMapping]
WHERE FCHbaID = @HostBusAdapterID
)

DELETE FROM [dbo].[tbl_ADHC_FCHbaToFibrePortMapping]
WHERE FCHbaID = @HostBusAdapterID

PRINT N'Deleting fiber port with GUID ' + RTRIM(CAST(@FiberPortID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_FibrePort]
WHERE PortID = @FiberPortID

PRINT N'Deleting fiber channel mapping for host bus adapter with GUID ' + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_HostFibreChannelHba]
WHERE FCHbaID = @HostBusAdapterID

PRINT N'Deleting any iSCSI entries for host bus adapter with GUID ' + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DECLARE @iSCSITargets TABLE
(
TargetID GUID
)
INSERT INTO @iSCSITargets (TargetID)
SELECT TargetID FROM [dbo].[tbl_ADHC_ISCSIHbaToTargetMapping]
WHERE ISCSIHbaID = @HostBusAdapterID

PRINT N'Deleting iSCSI host bus adapter to target mapping for mapping for host bus adapter with GUID ' + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_ISCSIHbaToTargetMapping]
WHERE ISCSIHbaID = @HostBusAdapterID

PRINT N'Deleting iSCSI host bus adapter with GUID ' + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_HostInternetSCSIHba]
WHERE ISCSIHbaID = @HostBusAdapterID

PRINT N'Deleting iSCSI targets for host bus adapter with GUID ' + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DECLARE @iSCSITargetIDCursor CURSOR;
DECLARE @iSCSITargetID GUID;
SET @iSCSITargetIDCursor = CURSOR FOR
(SELECT TargetID FROM @iSCSITargets)

OPEN @iSCSITargetIDCursor

FETCH NEXT FROM @iSCSITargetIDCursor INTO @iSCSITargetID

WHILE (@@FETCH_STATUS = 0)
BEGIN

PRINT N'Deleting iSCSI targets with GUID ' + RTRIM(CAST(@iSCSITargetID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_ISCSITarget]
WHERE TargetID = @iSCSITargetID

FETCH NEXT FROM @iSCSITargetIDCursor INTO @iSCSITargetID
END

CLOSE @iSCSITargetIDCursor
DEALLOCATE @iSCSITargetIDCursor

FETCH NEXT FROM @HostBusAdapterCursor INTO @HostBusAdapterID
END

CLOSE @HostBusAdapterCursor
DEALLOCATE @HostBusAdapterCursor

PRINT N'Completing host bus adapters deletion'

DELETE FROM [dbo].[tbl_ADHC_HostBusAdapter]
WHERE HostID = @DeleteHostId

PRINT N'Prepairing to delete agent servers'

DECLARE @AgentServerID  GUID;
SET @AgentServerID =
(
SELECT AgentServerID FROM [dbo].[tbl_ADHC_AgentServerRelation]
WHERE HostLibraryServerID = @DeleteHostID
)

PRINT N'Deleting agent server relations'

DELETE FROM [dbo].[tbl_ADHC_AgentServerRelation]
WHERE HostLibraryServerID = @DeleteHostID

PRINT N'Deleting health monitor data for agent server with GUID ' + RTRIM(CAST(@AgentServerID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_HealthMonitor]
WHERE AgentServerID = @AgentServerID

PRINT N'Deleting agent server with GUID ' + RTRIM(CAST(@AgentServerID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_AgentServer]
WHERE AgentServerID = @AgentServerID

PRINT N'Deleting host GPUs'

DELETE FROM [dbo].[tbl_ADHC_HostGPU]
WHERE HostID = @DeleteHostId

PRINT N'Deleting host'

DELETE FROM [dbo].[tbl_ADHC_Host]
WHERE HostID = @DeleteHostId

IF (@HostClusterID IS NOT NULL)
BEGIN

PRINT N'Checking to see if any other hosts are joined to the same cluster'

DECLARE @HostCount INT;
SET @HostCount =
(
SELECT COUNT(*) FROM [dbo].[tbl_ADHC_Host]
WHERE HostClusterID = @HostClusterID
)

PRINT N'There are ' + RTRIM(CAST(@HostCount AS nvarchar(50))) + N' currently joined to the same cluster'

IF (@HostCount = 0)
BEGIN

PRINT N'Deleting cluster disks'

DELETE FROM [dbo].[tbl_ADHC_ClusterDisk]
WHERE ClusterID = @HostClusterID

PRINT N'Deleting cluster'

DELETE FROM [dbo].[tbl_ADHC_HostCluster]
WHERE ClusterID = @HostClusterID
END
ELSE
PRINT N'This host is not the last host in the cluster, the cluster will be deleted upon the deletion of the last host.'
END
ELSE
PRINT N'This host does not belong to a cluster, no clusters will be deleted'

GO



After the script completes you should be able to start up the VMM service again and the stubborn host should be gone.

18 March 2015

SCVMM console takes forever to open : Fixed

I had a problem when launching the SCVMM console, I would get the log in prompt fast enough but it would then just sit there for about 5 minutes before it would actually open up.  From that point on everything worked perfectly fine again.

Turn out the problem was because the SCOM ( System Center Operations Manager) server had gone offline.

You can confirm that this is the same problem by looking at Settings | System Centre Settings | Operations Manager Server



If you attempt to make a change to any of these settings it will again bog down for a few minutes not doing anything. but then it will give you the solution.


Run the following from PowerShell as an admin

Remove-SCOpsMgrConnection -force

The defunct SCOM server is removed and then you are free to add a new one in again.



02 March 2015

Change host access account for a cluster in SCVMM

The host access account is the one used by VMM to communicate with the hosts.  This can normally easily be changed using the hosts's properties.

If however the host is a cluster member the  host Access Run as account is greyed out, more specifically the Browse button that would allow you to select another run as account.



You can check which hosts are using a particular run as account by selecting it form the
Settings | Security |Run as accounts | Properties | Consumers

To change the host access acount we are goign to need to head over to PowerShell

You need to confirm the clustername and Run As names before you start. you can get those with

Get-SCVMHostCluster

Get-SCRunAsAccount

Once you have that simply run the following

$YourCluster = Get-SCVMHostCluster -Name clustername
$YourRunAs = Get-SCRunAsAccount -Name "runasaccoutname"
Set-SCVmHostCluster -VMHostCluster $YourCluster -VMHostManagementCredential $YourRunAs

After the script has run you can verify thing through the VMM console again.


Originally posted as a solution by M.Oberg