Posted in Windows Powershell | 1 Comment | 449 views | 23/04/2013 16:55
Hello,
PoSHStats for Exchange Server v2.2 is almost ready!
I’m releasing latest version for tests. Please let me know if you find any bugs etc.
Main Screenshot:

Example of Exchange Host Reporting:

Example of Mailbox Database Reporting:

Example of User Mailbox Reporting:

It has a nice limit information bar :)

Also you can see service status of Exchange hosts:

This is not the final version of PoSHStats.
There will be more features for Exchange but I think this version is enough for many enterprises.
Tested with 3000 mailboxes, everything seems ok. First time setup will take about 5-10 minutes depends on your environment.
First download setup:
Install setup.exe. After installation, open PowerShell and:
1
2
| Import-Module PoSHStats
Start-PoSHStats |
Give your hostname (like reports.poshstats.net or 192.168.2.1) and port number, then you are free to go.
Thanks for using PoSHStats.
Yusuf.
Posted in Virtual Machine Manager, Windows Powershell | 10 Comments | 3,232 views | 04/04/2013 20:25
Hi guys and ladies! :)
Update: v1.4 is here! Thanks for your feedbacks.
Hyper-V VM Migration Script is ready! Now it’s possible to migrate your VMs from Hyper-V v2 to Hyper-V v3 with quick migration capabilities.
It supports following scenarios:
1. Standalone Hyper-V v2 Host
2. Hyper-V v2 Host in trusted domain
3. Hyper-V v2 Host in untrusted domain
Update v1.4:
1. Fixed network configuration issue on different subnets
2. Improved debugging
Update v1.3:
1. Added support for servers on different subnets
Update v1.2:
1. Linux VM migration support
2. Fixed a bug while getting vhd name
3. Advanced debugging switch (use -DebugMode)
So why it supports untrusted domains? Because you may not want to install Windows Server 2012 Cluster into your existing Windows Server 2008 R2 environment. If you have totally different environment for Hyper-V v3, then this script is your best friend.
Advantages:
1. It supports BITS! It’s ready to move large VHD files.
2. It supports “Rollback“. If there will be any problem, this script will undo any changes!!! :)
3. Licensed in GPLv2. You can use this script in your organization without any licensing issues. Totally free!
How to Install?
1. First download Hyper-V VM Migration Script:
Download Script
2. You can use exe or msi file to installation. I’ve just used migration.exe file to installation.

3. Change Powershell path if you have different drive path.

4. Click Install to begin installation.

5. That’s it! You can start using migration script.

6. Go to Powershell and type following to change execution policy as “AllSigned”.
Set-ExecutionPolicy AllSigned |

7. Allow my code publishing certificate. This will prevent you to run untrusted scripts.

8. Installation is done! Now we can start migration of virtual machines.
How to use?
Example 1: If want to migrate VM01 from HV001 (10.10.10.2) to your local Hyper-V v3 host, use following:
New-Migration -VMName "VM01" -VMHost "HV001" -VMPath "C:\ClusterStorage\Volume1" |
BTW, -VMPath switch is the destination path. Not your current VM path. This script finds VM path automatically.
Example 2: If HV001 (10.10.10.2) is a standalone machine, use following:
New-Migration -VMName "VM01" -VMHost "10.10.10.2" -Username "Administrator" -Password "123456" -VMPath "C:\ClusterStorage\Volume1" |
Example 3: If HV001 (10.10.10.2) is a member of a untrusted domain, use following:
New-Migration -VMName "VM01" -VMHost "10.10.10.2" -Username "Domain\Administrator" -Password "123456" -VMPath "C:\ClusterStorage\Volume1" |
Example 4: Having trouble with migration? Use debugging switch (-DebugMode) to see what really makes that problem:
New-Migration -VMName "VM01" -VMHost "10.10.10.2" -VMPath "C:\ClusterStorage\Volume1" -DebugMode |
Requirements:
1. You should install this script on to your Hyper-V v3 host.
2. This script doesn’t allow you to migrate VMs if they have snapshots. You should remove them first.
3. Requires Powershell v3. (It comes by default on Windows Server 2012)
4. Hyper-V v2 host and Hyper-V v3 host should have same network switch names. If they are different, this script connects first external network to your virtual machine.
Thanks for using Hyper-V VM Migration script!
-Yusuf.
Posted in Windows Powershell | No Comment | 2,165 views | 27/03/2013 11:03
When you remove an Exchange Mailbox from DAG or your environment, msExchHomeServerName attribute remains same. You may get problem when you try to update user mailbox due to non exist Mailbox Server. In order to achieve this problem, you should get affected mailboxes first, then you should update them with correct mailbox server name.
First get all affected mailboxes:
$Mailboxes = Get-Mailbox -ResultSize Unlimited | where {$_.Servername -eq "Old_Mailbox_Name"} |
Update them with this:
1
2
3
4
5
6
7
| foreach ($Mailbox in $Mailboxes)
{
Write-Host $Mailbox.Name
$MBX = $null;
$MBX = Get-Mailbox -Identity $Mailbox
Set-Mailbox $MBX -Database $MBX.Database -Confirm:$false -Force -Verbose
} |
After that process, all msExchHomeServerName will be corrected.
Posted in Windows Powershell | No Comment | 273 views | 23/03/2013 08:30
Merhaba,
Portal yapımı sırasında kullandığım kodlar aşağıda:
New-SQLDatabaseBackup:
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
| function New-SQLDatabaseBackup {
param (
# Instance Name
[Parameter(
Mandatory = $true,
HelpMessage = 'Instance Name of SQL Server.')]
$ServerInstance,
# Database Name
[Parameter(
Mandatory = $true,
HelpMessage = 'Database Name.')]
$Database,
# Debug Mode
[Parameter(
Mandatory = $false,
HelpMessage = 'Debug Mode')]
[switch]$DebugMode = $false
)
# Enable Debug Mode
if ($DebugMode)
{
$DebugPreference = "Continue"
}
else
{
$ErrorActionPreference = "silentlycontinue"
}
# Date and Time Calculation
$JobTime = Get-Date -format HHmm
$HourString = (Get-Date).ToString("HH")
$MinuteString = (Get-Date).ToString("mm")
$DayString = (Get-Date).ToString("dd")
$MonthString = (Get-Date).ToString("MM")
$YearString = (Get-Date).ToString("yyyy")
Write-Debug "Jobtime: $JobTime"
# Log File
$LogFile = "C:\Program Files\Microsoft SQL Server\MSSQL11.SYSADMINSQL\MSSQL\Backup\backup_logs.txt"
# Backup File
$BackupFile = "C:\Program Files\Microsoft SQL Server\MSSQL11.SYSADMINSQL\MSSQL\Backup\" + $Database + "_" + $Jobtime + "_" + $DayString + $MonthString + $YearString + ".bak"
# XML Output Path
$XMLOutputPath = "C:\reports.xml"
# Backup Database
$BackupSQLDB = Backup-SqlDatabase -Database $Database -ServerInstance $ServerInstance -Checksum -Initialize -CompressionOption On -BackupFile $BackupFile
# Get Backup Size
$TestBackup = Test-Path -Path $BackupFile
if ($TestBackup)
{
$BackupSize = (Get-Item $BackupFile).Length / 1MB
}
else
{
$BackupSize = "0"
}
# Backup Status
if ($TestBackup)
{
$Status = "OK"
}
else
{
$Status = "Failed"
}
# Log Content
$LogContent = $Database + ";" + $HourString + ":" + $MinuteString + " " + $DayString + "." + $MonthString + "." + $YearString + ";" + $BackupSize + ";" + $Status
# Log Backup Job
Add-Content -Value $LogContent -Path $LogFile
# Get Log Output
$LogOutput = Get-Content -Path $LogFile
# XML Header
$BackupXML = "<?xml version=""1.0"" encoding=""utf-8""?>`n"
$BackupXML += "<Result>`n"
$BackupXML += " <Code>1</Code>`n"
$BackupXML += " <Message>Operation is completed</Message>`n"
foreach ($LogContent in $LogOutput)
{
$Log = $LogContent.Split(";")
$DBName = $Log[0]
$BackupDate = $Log[1]
$BackupSize = $Log[2]
$BackupSize = ([math]::round(($BackupSize), 0))
$Status = $Log[3]
# Backup Reports
$BackupXML += " <OperationResult>`n"
$BackupXML += " <DBName>$DBName</DBName>`n"
$BackupXML += " <BackupDate>$BackupDate</BackupDate>`n"
$BackupXML += " <BackupSize>$BackupSize</BackupSize>`n"
$BackupXML += " <Status>$Status</Status>`n"
$BackupXML += " </OperationResult>`n"
}
# XML Footer
$BackupXML += "</Result>`n"
# XML Output
Clear-Content -Path $XMLOutputPath
Add-Content -Value $BackupXML -Path $XMLOutputPath
} |
Twitter üzerinden komut çekerken kullandığım kodlar:
1
2
3
4
5
6
7
8
9
| # Twitter
$Request = New-Object -ComObject Msxml2.XMLHTTP
$APIURL = "https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=yusufozturk&count=1"
$Request.open('GET', $APIURL, $false)
$Request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
$Request.setRequestHeader("Content-length", $Parameters.length)
$Request.setRequestHeader("Connection", "close")
$Request.send($Parameters)
$Response = [xml]$Request.responseText |
Portal, mevcut olan PoSHStats template’i ile oluşturuldu. Table kısmı aşağıda:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <!-- SQL Server Backup Reports -->
<script type="text/javascript" src="js/custom/jquery.sql.backupreports.js"></script>
<div class="table">
<div class="head"><h5 class="iStats">Backup Reports</h5></div>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="SQL">
<thead>
<tr>
<th>Database Name</th>
<th>Backup Date</th>
<th>Backup Size (MB)</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div> |
Bu komutları sunum sırasında sıfırdan yazmak zor olacak ama deneyeceğiz bakalım :)
Posted in Virtual Machine Manager, Windows Powershell | No Comment | 2,837 views | 12/10/2012 11:55
1. How to create RunAs Account?
1
2
3
| $SecurePassword = ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "yusufozturk\Administrator", $SecurePassword
New-SCRunAsAccount -Name "Domain Admin" -Credential $Credential |
2. How to get RunAs Account?
1
| Get-SCRunAsAccount -Name "Domain Admin" |
3. How to remove RunAs Account?
1
| Get-SCRunAsAccount -Name "Domain Admin" | Remove-SCRunAsAccount |

Posted in Virtual Machine Manager, Windows Powershell | No Comment | 2,445 views | 10/10/2012 14:25
Somehow, you have to migrate a new Hyper-V v3 VM back to Hyper-V v2 environment?
Then you may need to follow these steps.
Of course if you need to migrate a VM from Hyper-V v2 to Hyper-V v3, you can use this script for quick migration:
If you export a virtual machine from Hyper-V v3 and try to import Hyper-V v2, Hyper-V gives this error:

Because Hyper-V v3 export is not compatible with old version of Hyper-V.
Hyper-V v3 exports only XML config file, but Hyper-V v2 exports .exp file.
Achieve this problem, you need to use this Powershell export script on Hyper-V v3.
Before exporting virtual machine, do following steps:
1. Remove your all disks file from virtual machines.
2. Change your virtual machine switch as “Not Connected”.
Thanks to Ben, this script exports VM config in Hyper-V v2 style.
Now download EXP template from here:
Open your exported .exp file and template.exp file in the zip file with a text editor.
You will see $Replace1, $Replace2, $Replace3 and $Replace4 in template.exp.
You should change them with your exported .exp file values.
Follow these steps for modification:
1. Replace this one with your virtual machine GUID: $Replace1
2. Replace this one with your virtual machine name: $Replace2
3. Replace this one with your virtual machine MAC address: $Replace3
4. Replace this one with your virtual machine ethernet port GUID: $Replace4
5. Finally, replace template.exp file name with your exported .exp file name.
Now you can import it to Hyper-V v2. After import, you can attach your virtual disks to VM again.
Finally change your virtual machine switch and VLAN configuration. Now you can start your VM.
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 829 views | 29/09/2012 07:56
SetLinuxVM v5 is out! It’s the best Linux VM preparation solution for Hyper-V on the market. But what’s changed with SetLinuxVM v5 and how it’s become fastest solution on the market?
1. Executing scripts instead of sending codes
In previous versions of SetLinuxVM, the idea was sending commands to virtual machine via Wmi interface. It was a great idea and nicely worked for 4 great versions of SetLinuxVM. But it took more than 5 minutes for a full preparation and it was a long time. So I made scripts and executing script is just easy and error-free.
Lets see old style of wmi code:
$SendCommand = $VMConsole.TypeText('echo "iface $iface inet static" >>/etc/network/interfaces'); |
Now I just use that way to execute scripts:
$SendCommand = $VMConsole.TypeText(". $ScriptPrefix-Unattended.sh"); |
Also now it’s easier to change scripts as your way. Sample timezone configuration script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| # Change Time Zone Configuration
If ($TimeZone)
{
$TimeZoneScript = "echo Setting Time Zone.." + "`n"
$TimeZoneScript += "ln -sf /usr/share/zoneinfo/$TimeZone /etc/localtime" + "`n"
$TimeZoneScript += "rm -f /etc/sysconfig/clock" + "`n"
$TimeZoneScript += "echo ZONE=`"$TimeZone`" >>/etc/sysconfig/clock" + "`n"
$TimeZoneScript += "echo 'UTC=true' >>/etc/sysconfig/clock" + "`n"
$TimeZoneScript += "echo 'ARC=false' >>/etc/sysconfig/clock" + "`n"
$TimeZoneScript += "echo End of Time Zone."
# Prepare Time Zone Script
Add-Content -Value $TimeZoneScript -Path "$UnattendedScriptPath\$ScriptPrefix-Unattended.sh"
} |
If you are familiar with Linux Bash scripting, it is very easy to modify these codes for your requirements.
2. Linux Integration Components 3.4
With new Linux integration components, SetLinuxVM is now able to install LIC on CentOS/RHEL 5 and CentOS/RHEL 6.
So how do I know which distro are you using? It’s simple. I’m getting distro name with this command.
distro=$(cat /etc/issue | head -n 2 | tr -d "\n" | tr "[:upper:]" "[:lower:]") |
This gives the distro name. I use if/else statement to install it on your distro.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| $InstallLICScript += 'if [[ $distro == *6.0* ]] || [[ $distro == *6.1* ]] || [[ $distro == *6.2* ]]; then' + "`n"
$InstallLICScript += "cd RHEL6012" + "`n"
$InstallLICScript += "./install.sh" + "`n"
$InstallLICScript += 'elif [[ $distro == *6.3* ]]; then' + "`n"
$InstallLICScript += "cd RHEL63" + "`n"
$InstallLICScript += "./install.sh" + "`n"
$InstallLICScript += 'elif [[ $distro == *5.7* ]]; then' + "`n"
$InstallLICScript += "cd RHEL57" + "`n"
$InstallLICScript += "./install-rhel57.sh" + "`n"
$InstallLICScript += 'elif [[ $distro == *5.8* ]]; then' + "`n"
$InstallLICScript += "cd RHEL58" + "`n"
$InstallLICScript += "./install-rhel58.sh" + "`n"
$InstallLICScript += "else" + "`n"
$InstallLICScript += "echo Current distribution is not supported." + "`n"
$InstallLICScript += "fi" + "`n" |
I talked about technical details of SetLinuxVM v5. I hope you enjoyed it. Thanks for using SetLinuxVM!
|