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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 3,584 views | 23/06/2009 01:43

You can create MySQL user from Powershell with MySQL connector:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Powershell Args
$dbusername = $args[0]			# user01073
$dbpassword = $args[1]			# RadoreTelekom
$dbname = $args[2]     			# db01073
 
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
 
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
 
# Create MySQL User
$createmysqluser = "CREATE USER '" + $dbusername  + "'@'localhost'"
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($createmysqluser, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)

Also I used arguments so you can call this powershell script from your panel.


Posted in Hosting & IIS7, Windows Powershell, Windows Server | No Comment | 4,128 views | 23/06/2009 01:39

You can create MySQL database from Powershell with MySQL connector:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Powershell Args
$dbusername = $args[0]			# user01073
$dbpassword = $args[1]			# RadoreTelekom
$dbname = $args[2]     			# db01073
 
# Add MySQL Data Connector
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
 
# Open Connection to SQL Server
$connStr = "server=127.0.0.1;port=3306;uid=root;pwd=SQLPassword"
$conn = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$conn.Open()
 
# Create MySQL Database
$createmysqldatabase = 'CREATE DATABASE `' + $dbname + '`'
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($createmysqldatabase, $conn)
$da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$ds = New-Object System.Data.DataSet
$da.Fill($ds)

Also I used arguments so you can call this powershell script from your panel.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 7,751 views | 20/06/2009 08:42

I will list all virtual machines and their ip address, then I will export this informations to Argus, so I can see all virtual machines status with Argus or similar network traffic controller. You can’t get ip address with this method because it’s not possible, at least now. I used MSSQL server to get CIDRs of virtual machines.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
$VMProp = Get-VM | Select-Object -Property Name,OperatingSystem
foreach ($i in $VMProp)
{
	$VMName = $i.Name
	$VMIP = $i.IPAddress
 
             $valueone = '        Host "' + $VMName + '" {'
             $valuetwo = '                hostname: ' + $VMIP
             $valuethree = '                Service TCP/HTTP'
             $valuefour = '        }'
 
	add-content -path “C:\argus.txt” -value $valueone
	add-content -path “C:\argus.txt” -value $valuetwo
	add-content -path “C:\argus.txt” -value $valuethree
	add-content -path “C:\argus.txt” -value $valuefour
}

You can copy Argus.txt codes and past it to your Argus config file, \var\argus\config.php.


Posted in Virtual Machine Manager, Windows Powershell | 1 Comment | 5,678 views | 20/06/2009 08:32

Lets list all Virtual Machines in our environment with Powershell.

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
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
$VMProp = Get-VM | Select-Object -Property Name,OperatingSystem
clear-content -path "C:\VMList.txt"
$vxcount=0;
$vmcount=0;
foreach ($i in $VMProp)
{
	$VMName = $i.Name
	$VMOprs = $i.OperatingSystem.Name
 
	IF ($VMName -like "VM*")
		{
			IF ($VMName -eq "VMM")
				{
					#
				}
			ELSE
				{
					add-content -path “C:\VMList.txt” -value $VMName	
					add-content -path “C:\VMList.txt” -value $VMOprs
					add-content -path “C:\VMList.txt” -value ‘‘
					$vmcount=$vmcount+1;
				}
		}
 
	IF ($VMName -like "VX*")
		{
			add-content -path “C:\VMList.txt” -value $VMName
			add-content -path “C:\VMList.txt” -value $VMOprs
			add-content -path “C:\VMList.txt” -value ‘‘
			$vxcount=$vxcount+1;
		}
}
 
write-host You have $vxcount VXs and $vmcount VMs.
$total=$vxcount+$vmcount
write-host Total: $total

We have two type of Virtual Machines called VM and VX. I listed them separately. But I have a machine called VMM, so I excluded that virtual machine.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 7,585 views | 20/06/2009 08:21

You can change vlan id of virtual machines with Powershell:

1
2
3
4
5
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
$VMNO = $args[0]
$VLANID = $args [1]
get-vm $VMNO | Get-VirtualNetworkAdapter | Set-VirtualNetworkAdapter -VLANEnabled $true -VLANID $VLANID

If you need to disable Vlan, just use $false for -VLANEnabled.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 3,054 views | 20/06/2009 08:18

You can change owners of the virtual machines with Powershell:

1
2
3
4
5
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
$VMNO = $args[0]
$USERNO = $args[1]
Set-VM $VMNO -Owner SCVMM\USER$USERNO

This method could be used for suspending Virtual Machines.


Posted in Virtual Machine Manager, Windows Powershell | No Comment | 1,726 views | 19/06/2009 23:23

Hyper-v allocates ram and you can’t create more virtual machines if you don’t have enough ram on your hyperv servers. If you have an automatic deploy script, you can miss available rams on Hyperv servers. So I created a script, checking all hyperv servers and if ram is less than a limit, it sends you an order mail.

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
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
 
$VMHostProp = Get-VMHost hyperv*
$BestServer = $VMHostProp | sort-object AvailableMemory | Select-Object -Last 1
$VMCount = $BestServer.VMs.Count
 
IF ($BestServer.AvailableMemory -lt "1500")
{
$satir01 = 'Hello,'
$satir02 = ' '
$satir03 = 'There are not enough rams on Hyperv servers.'
$satir04 = 'Maximum available ram is on ' + $BestServer.Name + ' server.'
$satir05 = ' '
$satir06 = 'For more information, ' + $BestServer.Name + ' specifications:'
$satir07 = 'Available ram: ' + $BestServer.AvailableMemory
$satir08 = 'Total vms on server: ' + $VMCount
$satir09 = 'Total hdds on server: ' + $BestServer.DiskVolumes.Count
$satir10 = ' '
$satir11 = 'Regards,'
$satir12 = 'Powershell'
clear-content -path "C:\VMMLibrary\stokdurumu.txt"
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir01
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir02
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir03
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir04
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir05
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir06
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir07
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir08
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir09
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir10
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir11
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir12
C:\VMMLibrary\mail.exe -s mx.gmail.com -t team@yusufozturk.info -f status@yusufozturk.info -h -a "Hyperv Status" -m C:\VMMLibrary\stokdurumu.txt -c
}

Mail.exe is a mail sender exe for command prompt. You can easily find a cmd mailer for this scenario.