Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 3,577 views | 22/08/2013 10:12
This is pretty cool and detailed report for VMs with Dynamic Disk. It requires SCVMM 2012 to get details but it’s possible to change it to use Hyper-V PowerShell Cmdlet.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| $VMs = Get-VM
foreach ($VM in $VMs)
{
$Disks = Get-VM $VM | Get-SCVirtualHardDisk
foreach ($Disk in $Disks)
{
if ($Disk.VHDType -ne "FixedSize")
{
$DiskLocation = $Disk.Location
$CSVVolume = ($Disk.Location.Split("\"))[2]
$DiskName = ($Disk.Location.Split("\"))[-1]
$DiskSize = ([math]::round(($Disk.Size/1GB), 0))
$DiskMSize = ([math]::round(($Disk.MaximumSize/1GB), 0))
$DiskHost = $Disk.VMHost
$CSVFreeSpace = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").FreeSpace/1GB), 0))
$CSVCapacity = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").Capacity/1GB), 0))
$Value = $VM.Name + ";" + $DiskName + ";" + $CSVVolume + ";" + $CSVFreeSpace + ";" + $CSVCapacity + ";" + $DiskMSize + ";" + $DiskSize + ";" + $DiskHost
Add-Content -Path DiskUsage.txt -Value $Value
}
}
} |
$VMs = Get-VM
foreach ($VM in $VMs)
{
$Disks = Get-VM $VM | Get-SCVirtualHardDisk
foreach ($Disk in $Disks)
{
if ($Disk.VHDType -ne "FixedSize")
{
$DiskLocation = $Disk.Location
$CSVVolume = ($Disk.Location.Split("\"))[2]
$DiskName = ($Disk.Location.Split("\"))[-1]
$DiskSize = ([math]::round(($Disk.Size/1GB), 0))
$DiskMSize = ([math]::round(($Disk.MaximumSize/1GB), 0))
$DiskHost = $Disk.VMHost
$CSVFreeSpace = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").FreeSpace/1GB), 0))
$CSVCapacity = ([math]::round(((Get-SCStorageVolume | where VMHost -eq $DiskHost | Where Name -like "*$CSVVolume*").Capacity/1GB), 0))
$Value = $VM.Name + ";" + $DiskName + ";" + $CSVVolume + ";" + $CSVFreeSpace + ";" + $CSVCapacity + ";" + $DiskMSize + ";" + $DiskSize + ";" + $DiskHost
Add-Content -Path DiskUsage.txt -Value $Value
}
}
}
It also shows CSV volume name, capacity and free space information.
Posted in Windows Powershell, Windows Server | No Comment | 1,941 views | 18/08/2013 00:25
You can check Windows Server 2012 version with following script:
1
2
3
4
5
6
7
8
9
10
11
12
| $Servers = Get-Content "C:\Servers.txt"
foreach ($Server in $Servers)
{
Write-Host "--------------------"
Write-Host $Server
$Version = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Server).Version
Write-Host $Version
if ($Version -like "6.2*")
{
Add-Content -Value $Server -Path C:\Windows2012Servers.txt
}
} |
$Servers = Get-Content "C:\Servers.txt"
foreach ($Server in $Servers)
{
Write-Host "--------------------"
Write-Host $Server
$Version = (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Server).Version
Write-Host $Version
if ($Version -like "6.2*")
{
Add-Content -Value $Server -Path C:\Windows2012Servers.txt
}
}
That will output all results into Windows2012Servers.txt file.
Posted in Windows Powershell, Windows Server | No Comment | 12,364 views | 17/08/2013 22:41
This is pretty cool script after patch updates to check which servers are successfully rebooted.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| $Servers = Get-Content C:\UpdateServers.txt
function WMIDateStringToDate($Bootup) {
[System.Management.ManagementDateTimeconverter]::ToDateTime($Bootup)
}
foreach ($Server in $Servers)
{
$OS = Get-WmiObject Win32_OperatingSystem -ComputerName $Server
$Bootup = $OS.LastBootUpTime
$LastBootUpTime = WMIDateStringToDate($Bootup)
$Now = Get-Date
$Uptime = $Now - $LastBootUpTime
$d = $Uptime.Days
$h = $Uptime.Hours
$m = $uptime.Minutes
$ms= $uptime.Milliseconds
$a = "$Server Up for: {0} days, {1} hours, {2}.{3} minutes" -f $d,$h,$m,$ms
Write-Host "$a" -ForegroundColor Green
} |
$Servers = Get-Content C:\UpdateServers.txt
function WMIDateStringToDate($Bootup) {
[System.Management.ManagementDateTimeconverter]::ToDateTime($Bootup)
}
foreach ($Server in $Servers)
{
$OS = Get-WmiObject Win32_OperatingSystem -ComputerName $Server
$Bootup = $OS.LastBootUpTime
$LastBootUpTime = WMIDateStringToDate($Bootup)
$Now = Get-Date
$Uptime = $Now - $LastBootUpTime
$d = $Uptime.Days
$h = $Uptime.Hours
$m = $uptime.Minutes
$ms= $uptime.Milliseconds
$a = "$Server Up for: {0} days, {1} hours, {2}.{3} minutes" -f $d,$h,$m,$ms
Write-Host "$a" -ForegroundColor Green
}
I hope that helps :)
Posted in Virtual Machine Manager, Windows Powershell | No Comment | 2,666 views | 15/08/2013 10:25
You may export and move a VM to another host or volume, or maybe you may delete a VM but configuration and VHD files may still exist on old location. In that case, you can use this script to find that old VM directories.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| # Get Cluster Nodes
$ClusterNodes = "Cluster01Node01","Cluster02Node02"
foreach ($ClusterNode in $ClusterNodes)
{
$Volumes = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\
foreach ($Volume in $Volumes)
{
$ConfigFolders = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\$Volume
foreach ($ConfigFolder in $ConfigFolders)
{
$Result = "0";
$VMName = "";
$ClusterNodes = Get-Cluster $ClusterNode | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
$VMs = Get-VM -ComputerName $ClusterNode
foreach ($VM in $VMs)
{
$FullName = $ConfigFolder.FullName
$FullPath = "C:\" + $FullName.Split("\")[4] + "\" + $FullName.Split("\")[5] + "\" + $FullName.Split("\")[6]
if ($FullPath -like $VM.ConfigurationLocation)
{
$Result = 1;
}
$VirtualDisks = Get-VM -ComputerName $ClusterNode -Name $VM.Name | Get-VMHardDiskDrive
foreach ($VirtualDisk in $VirtualDisks)
{
if ($VirtualDisk.Path -like "$FullPath*")
{
$Result = 1;
}
}
}
}
if ($Result -ne "1")
{
Write-Warning $ConfigFolder.FullName
}
}
}
} |
# Get Cluster Nodes
$ClusterNodes = "Cluster01Node01","Cluster02Node02"
foreach ($ClusterNode in $ClusterNodes)
{
$Volumes = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\
foreach ($Volume in $Volumes)
{
$ConfigFolders = Get-ChildItem -Directory -Path \\$ClusterNode\C$\ClusterStorage\$Volume
foreach ($ConfigFolder in $ConfigFolders)
{
$Result = "0";
$VMName = "";
$ClusterNodes = Get-Cluster $ClusterNode | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
$VMs = Get-VM -ComputerName $ClusterNode
foreach ($VM in $VMs)
{
$FullName = $ConfigFolder.FullName
$FullPath = "C:\" + $FullName.Split("\")[4] + "\" + $FullName.Split("\")[5] + "\" + $FullName.Split("\")[6]
if ($FullPath -like $VM.ConfigurationLocation)
{
$Result = 1;
}
$VirtualDisks = Get-VM -ComputerName $ClusterNode -Name $VM.Name | Get-VMHardDiskDrive
foreach ($VirtualDisk in $VirtualDisks)
{
if ($VirtualDisk.Path -like "$FullPath*")
{
$Result = 1;
}
}
}
}
if ($Result -ne "1")
{
Write-Warning $ConfigFolder.FullName
}
}
}
}
$ClusterNodes should contain different Cluster’s only one nodes. Using with that node name, we can query other nodes too.
Posted in Windows Server | No Comment | 3,608 views | 14/08/2013 09:22
You can create Microsoft SQL Server 2012 template on Hyper-V if you want to do unattended setups.
Follow the steps:
1) Install Windows Server 2012, do latest updates and your customizations.
2) Make a new folder called “Scripts” under “C:\Windows\Setup”. Path should be:
3) Make a new file called “SetupComplete.cmd” under “C:\Windows\Setup\Scripts”. Path should be:
C:\Windows\Setup\Scripts\SetupComplete.cmd |
C:\Windows\Setup\Scripts\SetupComplete.cmd
4) Mount SQL Server 2012 DVD and copy that into a directory like “C:\PATH\OF\MSSQL\”
5) Write SQL unattended setup commands into “SetupComplete.cmd”.
C:\PATH\OF\MSSQL\setup.exe /ConfigurationFile="C:\PATH\OF\MSSQL\ConfigurationFile.ini" /q |
C:\PATH\OF\MSSQL\setup.exe /ConfigurationFile="C:\PATH\OF\MSSQL\ConfigurationFile.ini" /q
6) You can use this ConfigurationFile.ini as a template and customize it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| ;SQL Server 2012 Configuration File
[OPTIONS]
ACTION="Install"
ENU="True"
UIMODE="Normal"
QUIET="False"
QUIETSIMPLE="False"
UpdateEnabled="False"
FEATURES=SQLENGINE,REPLICATION,FULLTEXT,CONN,IS,BC,SSMS,ADV_SSMS
UpdateSource="MU"
HELP="False"
INDICATEPROGRESS="False"
X86="False"
INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server"
INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server"
INSTANCENAME="MSSQLSERVER"
INSTANCEID="MSSQLSERVER"
SQMREPORTING="False"
ERRORREPORTING="False"
INSTANCEDIR="C:\Program Files\Microsoft SQL Server"
AGTSVCACCOUNT="NT Service\SQLSERVERAGENT"
AGTSVCSTARTUPTYPE="Manual"
ISSVCSTARTUPTYPE="Automatic"
ISSVCACCOUNT="NT Service\MsDtsServer110"
COMMFABRICPORT="0"
COMMFABRICNETWORKLEVEL="0"
COMMFABRICENCRYPTION="0"
MATRIXCMBRICKCOMMPORT="0"
SQLSVCSTARTUPTYPE="Automatic"
FILESTREAMLEVEL="0"
ENABLERANU="False"
SQLCOLLATION="Turkish_CI_AS"
SQLSVCACCOUNT="NT Service\MSSQLSERVER"
SQLSYSADMINACCOUNTS=".\Administrator"
SECURITYMODE="SQL"
ADDCURRENTUSERASSQLADMIN="False"
TCPENABLED="1"
NPENABLED="0"
BROWSERSVCSTARTUPTYPE="Disabled"
FTSVCACCOUNT="NT Service\MSSQLFDLauncher" |
;SQL Server 2012 Configuration File
[OPTIONS]
ACTION="Install"
ENU="True"
UIMODE="Normal"
QUIET="False"
QUIETSIMPLE="False"
UpdateEnabled="False"
FEATURES=SQLENGINE,REPLICATION,FULLTEXT,CONN,IS,BC,SSMS,ADV_SSMS
UpdateSource="MU"
HELP="False"
INDICATEPROGRESS="False"
X86="False"
INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server"
INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server"
INSTANCENAME="MSSQLSERVER"
INSTANCEID="MSSQLSERVER"
SQMREPORTING="False"
ERRORREPORTING="False"
INSTANCEDIR="C:\Program Files\Microsoft SQL Server"
AGTSVCACCOUNT="NT Service\SQLSERVERAGENT"
AGTSVCSTARTUPTYPE="Manual"
ISSVCSTARTUPTYPE="Automatic"
ISSVCACCOUNT="NT Service\MsDtsServer110"
COMMFABRICPORT="0"
COMMFABRICNETWORKLEVEL="0"
COMMFABRICENCRYPTION="0"
MATRIXCMBRICKCOMMPORT="0"
SQLSVCSTARTUPTYPE="Automatic"
FILESTREAMLEVEL="0"
ENABLERANU="False"
SQLCOLLATION="Turkish_CI_AS"
SQLSVCACCOUNT="NT Service\MSSQLSERVER"
SQLSYSADMINACCOUNTS=".\Administrator"
SECURITYMODE="SQL"
ADDCURRENTUSERASSQLADMIN="False"
TCPENABLED="1"
NPENABLED="0"
BROWSERSVCSTARTUPTYPE="Disabled"
FTSVCACCOUNT="NT Service\MSSQLFDLauncher"
7) Sysprep your Windows Server.
After these steps, you can deploy your VHD into different VMs.
Posted in Virtual Machine Manager, Windows Powershell | No Comment | 1,914 views | 12/08/2013 14:17
You can set User Role Quota for each Cloud Profile in SCVMM 2012 SP1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| $UserRoles = "BackOffice","CallCenter"
foreach ($UserRole in $UserRoles)
{
$UserRole = Get-SCUserRole $UserRole
$Clouds = "DMZ Cloud","Prod Cloud","Test Cloud"
foreach ($Cloud in $Clouds)
{
$MyCloud = Get-SCCloud $Cloud
$CloudUsage = Get-SCCloudUsage -Cloud $MyCloud -UserRole $UserRole
$CPUCount = $CloudUsage.CPUUsageCount
$Memory = $CloudUsage.MemoryUsageMB
$VMCount = $CloudUsage.VMUsageCount
[int]$NewCPUCount = [int]$CPUCount + 40;
[int]$NewMemory = [int]$Memory + 81920;
[int]$NewVMCount = [int]$VMCount + 10;
Get-SCUserRoleQuota -UserRole $UserRole -Cloud $MyCloud | Set-SCUserRoleQuota -CPUCount $NewCPUCount -MemoryMB $NewMemory -VMCount $NewVMCount
}
} |
$UserRoles = "BackOffice","CallCenter"
foreach ($UserRole in $UserRoles)
{
$UserRole = Get-SCUserRole $UserRole
$Clouds = "DMZ Cloud","Prod Cloud","Test Cloud"
foreach ($Cloud in $Clouds)
{
$MyCloud = Get-SCCloud $Cloud
$CloudUsage = Get-SCCloudUsage -Cloud $MyCloud -UserRole $UserRole
$CPUCount = $CloudUsage.CPUUsageCount
$Memory = $CloudUsage.MemoryUsageMB
$VMCount = $CloudUsage.VMUsageCount
[int]$NewCPUCount = [int]$CPUCount + 40;
[int]$NewMemory = [int]$Memory + 81920;
[int]$NewVMCount = [int]$VMCount + 10;
Get-SCUserRoleQuota -UserRole $UserRole -Cloud $MyCloud | Set-SCUserRoleQuota -CPUCount $NewCPUCount -MemoryMB $NewMemory -VMCount $NewVMCount
}
}
That will set on all profiles on $UserRoles array.
|