search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | No Comment | 1,544 views | 24/09/2013 10:31

There are some disk operations you can do in Windows Server 2012 with PowerShell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Getting Disk Signature
Get-Disk | ft FriendlyName, Signature
 
# Add Disk Signatures into Array
$Signatures = "4D53465420202020E55D0891031DB04CB1F2B507ED9FDC88","4D53465420202020E55D0891031DB04CB1F2B507ED9FDC89"
 
# Making Them Online
foreach ($Signature in $Signatures)
{
	Get-Disk | Where {$_.Signature -eq $Signature} | Set-Disk -IsOffline $False
}
 
# Making Them Offline
foreach ($Signature in $Signatures)
{
	Get-Disk | Where {$_.Signature -eq $Signature} | Set-Disk -IsOffline $True
}

Get-Disk is not available in Windows Server 2008 R2, so you should go with WMI.


Posted in Windows Powershell, Windows Server | No Comment | 1,812 views | 20/09/2013 10:40

This is my cluster checklist script to verify many different components like Windows Updates, Hotfixes, 3Par installation, Driver information etc.

1
2
3
4
5
6
7
8
9
10
# Lets get our master Cluster Node, thats one of the most updated Cluster Node
$MasterNode = ((Get-Cluster | Get-ClusterNode | Select Name,@{label="HotFixes";expression={(Get-Hotfix -ComputerName $_.Name).HotFixID.Count}} | Sort HotFixes -Descending)[0]).Name
 
# Get Master Hotfix KBs and put them in a array
$MasterHotfixes = @((Get-Hotfix -ComputerName $MasterNode).HotFixID)
 
# Now we will use that master hotfixes to compare with others
$ClusterResults = (Get-Cluster | Get-ClusterNode | Select Name,@{label="HP WBEM";expression={$ServerName = $_.Name; $TestWBEM = (Get-Item "\\$ServerName\C$\Program Files\HPWBEM\Tools\HPWbemTestEvent.exe").Exists; if ($TestWBEM -eq $True) { $TestWBEM = "True"; $TestWBEM; } else { $TestWBEM = "False"; $TestWBEM; }}},@{label="3PAR Info";expression={$ServerName = $_.Name; $Test3PAR = (Get-Item "\\$ServerName\C$\Program Files (x86)\3PAR\HP 3PARInfo\HP3PARInfo.exe").Exists; if ($Test3PAR -eq $True) { $Test3PAR = "True"; $Test3PAR; } else { $Test3PAR = "False"; $Test3PAR; }}},@{label="QLogic Driver";expression={$ServerName = $_.Name; (Get-Item \\$ServerName\C$\Windows\System32\Drivers\ql2300.sys).VersionInfo.ProductVersion}},@{label="HP SATA Driver";expression={$ServerName = $_.Name; (Get-Item \\$ServerName\C$\Windows\System32\Drivers\HPCISSs2.sys).VersionInfo.ProductVersion}},@{label="Total Hotfixes";expression={(Get-Hotfix -ComputerName $_.Name).HotFixID.Count}},@{label="Missing Hotfixes";expression={$Hotfixes = @((Get-Hotfix -ComputerName $_.Name).HotFixID); $MissingHotfixes = (Compare-Object -ReferenceObject $MasterHotfixes -DifferenceObject $Hotfixes).InputObject; if ($MissingHotfixes) { $MissingHotfixes } else { $MissingHotfixes = "No missing updates"; $MissingHotfixes } }} | Sort Name)
 
$ClusterResults

I hope it also helps you.


Posted in Windows Powershell, Windows Server | No Comment | 1,983 views | 17/09/2013 17:32

This is very useful script to get missing updates from your cluster nodes. Just run this on one of your Cluster node. Make sure you run PowerShell as (Domain) Administrator. Otherwise you can’t query your Cluster.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Yusuf Ozturk, 2013
# http://www.yusufozturk.info
 
# Lets get our master Cluster Node, thats one of the most updated Cluster Node
$MasterNode = ((Get-Cluster | Get-ClusterNode | Select Name,@{label="HotFixes";expression={(Get-Hotfix -ComputerName $_.Name).HotFixID.Count}} | Sort HotFixes -Descending)[0]).Name
 
# Get Master Hotfix KBs and put them in a array
$MasterHotfixes = @((Get-Hotfix -ComputerName $MasterNode).HotFixID)
 
# Now we will use that master hotfixes to compare with others
$HotfixResults = (Get-Cluster | Get-ClusterNode | Select Name,@{label="Total Hotfixes";expression={(Get-Hotfix -ComputerName $_.Name).HotFixID.Count}},@{label="Missing Hotfixes";expression={$Hotfixes = @((Get-Hotfix -ComputerName $_.Name).HotFixID); $MissingHotfixes = (Compare-Object -ReferenceObject $MasterHotfixes -DifferenceObject $Hotfixes).InputObject; if ($MissingHotfixes) { $MissingHotfixes } else { $MissingHotfixes = "No missing updates"; $MissingHotfixes } }} | Sort Name)
 
# You can get hotfix IDs like this
$HotfixResults[0].'Missing Hotfixes'

You will see pretty nice output :)


Posted in Windows Powershell, Windows Server | No Comment | 1,677 views | 17/09/2013 15:58

This might be useful to get Cluster Shared Volume (CSV) information from your cluster. Just run this on one of your Cluster node. Make sure you run PowerShell as (Domain) Administrator. Otherwise you can’t query your Cluster.

1
(Get-ClusterSharedVolume | Select -ExpandProperty SharedVolumeInfo | Select @{label="Name";expression={(($_.FriendlyVolumeName).Split("\"))[-1]}},@{label="Free Space (GB)";expression={([math]::round(((($_ | Select -Expand Partition).FreeSpace)/ 1GB), 0))}},@{label="Percent Free (%)";expression={([math]::round((($_ | Select -Expand Partition).PercentFree), 0))}},@{label="Total Space (GB)";expression={([math]::round(((($_ | Select -Expand Partition).Size)/ 1GB), 0))}} | Sort Name)

You will see pretty nice output.


Posted in Windows Powershell, Windows Server | No Comment | 1,583 views | 17/09/2013 11:48

This might be useful to get memory information from your cluster nodes. Just run this on one of your Cluster node. Make sure you run PowerShell as (Domain) Administrator. Otherwise you can’t query your Cluster.

1
(Get-Cluster | Get-ClusterNode | Select Name,@{label="Free Memory (GB)";expression={([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0))}},@{label="Free Memory (%)";expression={([math]::round(([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0))/([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0))*100))}},@{label="Total Memory (GB)";expression={([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0))}} | Sort Name)

You will see pretty nice output.


Posted in Windows Powershell | No Comment | 1,338 views | 09/09/2013 17:25

I’ve wrote 2 useful commands to find available memory and storage volume.

Getting most available CSV Volume by storage free space:

1
((Get-ClusterSharedVolume | Select -ExpandProperty SharedVolumeInfo | Select @{label="Name";expression={(($_.FriendlyVolumeName).Split("\"))[-1]}},@{label="FreeSpace";expression={($_ | Select -Expand Partition).FreeSpace}} | Sort FreeSpace -Descending)[0]).Name

Getting most available Hyper-V host by memory availability:

1
((Get-Cluster | Get-ClusterNode | Select Name,@{label="FreeMemory";expression={([math]::round(((Get-WmiObject -ComputerName $_.Name -Class Win32_OperatingSystem).FreePhysicalMemory / 1KB), 0))}} | Sort FreeMemory -Descending)[0]).Name

You can use Get-Cluster $ClusterName for remote Cluster support.


Posted in Windows Powershell, Windows Server | No Comment | 1,591 views | 06/09/2013 09:26

This is my automation script after Hyper-V 2012 installation.

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Disable Firewall
netsh advfirewall set allprofiles state off
 
# Disable UAC
Function Test-RegistryValue 
{
    param(
        [Alias("RegistryPath")]
        [Parameter(Position = 0)]
        [String]$Path
        ,
        [Alias("KeyName")]
        [Parameter(Position = 1)]
        [String]$Name
    )
 
    process 
    {
        if (Test-Path $Path) 
        {
            $Key = Get-Item -LiteralPath $Path
            if ($Key.GetValue($Name, $null) -ne $null)
            {
                if ($PassThru)
                {
                    Get-ItemProperty $Path $Name
                }       
                else
                {
                    $true
                }
            }
            else
            {
                $false
            }
        }
        else
        {
            $false
        }
    }
}
 
Function Disable-UAC
{
    $EnableUACRegistryPath = "REGISTRY::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System"
    $EnableUACRegistryKeyName = "EnableLUA"
    $UACKeyExists = Test-RegistryValue -RegistryPath $EnableUACRegistryPath -KeyName $EnableUACRegistryKeyName 
    if ($UACKeyExists)
    {
        Set-ItemProperty -Path $EnableUACRegistryPath -Name $EnableUACRegistryKeyName -Value 0
    }
    else
    {
        New-ItemProperty -Path $EnableUACRegistryPath -Name $EnableUACRegistryKeyName -Value 0 -PropertyType "DWord"
    }
}
Disable-UAC
 
# Disable IEESC
function Disable-IEESC
{
	$AdminKey = “HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}$UserKey = “HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}Set-ItemProperty -Path $AdminKey -Name “IsInstalled” -Value 0
	Set-ItemProperty -Path $UserKey -Name “IsInstalled” -Value 0
	Stop-Process -Name Explorer -Force
	Write-Host “IE Enhanced Security Configuration (ESC) has been disabled.” -ForegroundColor Green
}
Disable-IEESC
 
# Change Power Plan
function SetPowerPlan
{
    $PreferredPlan = "High performance"
    Write-Host "Setting Powerplan to $PreferredPlan" 
    $guid = (Get-WmiObject -Class win32_powerplan -Namespace root\cimv2\power -Filter "ElementName='$PreferredPlan'").InstanceID.tostring() 
    $regex = [regex]"{(.*?)}$" 
    $newpowerVal = $regex.Match($guid).groups[1].value
 
    # setting power setting to high performance 
    powercfg -S  $newpowerVal 
}
SetPowerPlan
 
# 3Par Command
fsutil behavior set disabledeletenotify 1
 
# Set Culture Configuration
Set-Culture tr-TR
Set-WinSystemLocale tr-TR
 
# Install Features
Copy-Item -Path "\\CLOUDLIB01\C$\SxS" -Destination "C:\SxS" -Recurse
Install-WindowsFeature -ConfigurationFilePath \\CLOUDLIB01\C$\Template\DeploymentConfigTemplate.xml -Source "C:\SxS"
 
# Install OV Client
Copy-Item -Path "\\CLOUDLIB01\C$\OV_x86x64" -Destination "C:\OV_x86x64" -Recurse
cd "C:\OV_x86x64"
.\setup.bat

You can create your own DeploymentConfigTemplate via Server Manager. You just need to export config.