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 | 2,663 views | 30/01/2012 01:36

Check-PSSnapin allows you to check specific PowerShell Snapin on server.
I’m using this function in SetLinuxVM 3.0 to check SCVMM if it’s available on server.

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
# Check Powershell Snapin
# Author: Yusuf Ozturk
# http://www.yusufozturk.info
 
function Check-PSSnapin
{
param (
    [Parameter(
        Mandatory = $true,
        HelpMessage = 'PowerShell Snapin Name. Example: Microsoft.SystemCenter.VirtualMachineManager')]
    [string]$Name
)
 
	$Success = "1";
	$CheckSnapin = Get-PSSnapin -Name $Name -EA SilentlyContinue
	if (!$CheckSnapin)
	{
		$AddSnapin = Add-PSSnapin -Name $Name -EA SilentlyContinue
		$CheckSnapin = Get-PSSnapin -Name $Name -EA SilentlyContinue
		if (!$CheckSnapin)
		{
			Write-Debug "$Name Snapin is not available."
		}
		else
		{
			Write-Debug "$Name Snapin is added."
			$Success
		}
	}
	else
	{
		Write-Debug "$Name Snapin is already loaded."
		$Success
	}
}

You can check PS Snapin like this:

Check-PSSnapin -Name "Microsoft.SystemCenter.VirtualMachineManager"

Name is mandatory, so you must give a name for that.



Posted in Windows Powershell, Windows Server | No Comment | 5,684 views | 30/01/2012 01:19

Check-WmiObject allows you to check Wmi provider/interface on given server.
I’m using this function in SetLinuxVM 3.0 to decide Hyper-V Manager.

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
# Check WMI Object
# Author: Yusuf Ozturk
# http://www.yusufozturk.info
 
function Check-WmiObject
{
param (
    [Parameter(
        Mandatory = $true,
        HelpMessage = 'Wmi NameSpace. Example: root\virtualization')]
    [string]$NameSpace,
 
    [Parameter(
        Mandatory = $false,
        HelpMessage = 'Name of the Wmi Host. Example: Server01')]
    [string]$WMIHost
)
 
	$Success = "1";
	if (!$WMIHost)
	{
		$CheckWmiObject = Get-WmiObject -Computer "." -Namespace "$NameSpace" -List -EA SilentlyContinue
		if (!$CheckWmiObject)
		{
			Write-Debug "Could not contact with Wmi Provider."
		}
		else
		{
			Write-Debug "Wmi Provider is available."
			$Success
		}
	}
	else
	{
		$CheckWmiObject = Get-WmiObject -Computer "$WMIHost" -Namespace "$NameSpace" -List -EA SilentlyContinue
		if (!$CheckWmiObject)
		{
			Write-Debug "Could not contact with Wmi Provider."
		}
		else
		{
			Write-Debug "Wmi Provider is available."
			$Success
		}
	}
}

You can check Wmi Provider like this:

Check-WmiObject -NameSpace "root\virtualization"

If you want to query different wmi host:

Check-WmiObject -NameSpace "root\virtualization" -WmiHost "Server01"

NameSpace is mandatory but you don’t need to type WmiHost if you query localhost.



Posted in Windows Powershell | 3 Comments | 7,769 views | 16/01/2012 23:43

I wrote a calendar sync script for Outlook to sync calendars between Exchange accounts. If you need to sync your calendars, accounts should be in same Outlook profile. I didn’t figure out how to sync between different profiles yet, but will work on 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
Function Sync-OutlookCalendar 
{
	# Connect to Outlook
	$Outlook = New-Object -com Outlook.Application
	# Get Calendars
	$Calendar1 = $Outlook.Session.folders.Item(1).Folders | where {$_.DefaultMessageClass -eq "IPM.Appointment"}
	$Calendar2 = $Outlook.Session.folders.Item(2).Folders | where {$_.DefaultMessageClass -eq "IPM.Appointment"}
	# Search Calendar Items
	$Calendar1Items = $Calendar1.items | Where {$_.Start -gt (Get-Date)} | Select-Object -Property Start, End, Subject, Location, MeetingStatus
	# Sync All: $Calendar1Items = $Calendar1.items | Select-Object -Property Start, End, Subject, Location, MeetingStatus
	# Sync Calendar Items
	Foreach ($Calendar1Item in $Calendar1Items)
	{
		$SearchDuplicate = $Calendar2.items | Where {$_.Start -eq $Calendar1Item.Start -and $_.End -eq $Calendar1Item.End -and $_.Subject -eq $Calendar1Item.Subject} | Select-Object -Property Start, End, Subject, Location, MeetingStatus
		if ($SearchDuplicate -eq $null)
		{
			$Appointment = $Calendar2.Items.Add(1)
			$Appointment.Start = $Calendar1Item.Start
			$Appointment.End = $Calendar1Item.End
			$Appointment.Subject = $Calendar1Item.Subject
			$Appointment.Location = $Calendar1Item.Location
			$Appointment.MeetingStatus = $Calendar1Item.MeetingStatus
			$Appointment.Save()
		}
		else
		{
			Write-Host "Appointment is already exist"
		}
	}
}

Every time you execute the script, it checks the duplicate entries. So you can’t sync if same appointment is also exist on other calendar. Also I thought to sync only new appointments, so there is a date checker too. You can change it if you want to sync all time appointments.


Posted in Virtual Machine Manager, Windows Powershell | 1 Comment | 3,221 views | 20/12/2011 21:41

If you have a public Hyper-V Cloud and use SCVMM, your customers can install Linux VM and install Hyper-V LIS v3.1 on it, there is nothing you can do to stop them. If they install it, you will not be able to use SCVMM due to LIS v3.1 bug.

System.ArgumentException: Version string portion was too short or too long.
at System.Version..ctor(String version)
at Microsoft.Carmine.ViridianImplementation.VirVMIntegrationService.PopulateKVPElements()

There are 2 options to prevent this.
1) You can provision all new virtual machines without Data Exchange offer.
2) You can disable Data Exchange offer only from Linux VMs to prevent that kind of problem.

If you have 0 – 50 VMs, it’s easy to deal with. But if you are a large Cloud provider, you can’t do it manually, you need scripting. So if you execute this command on SCVMM Powershell Interface, it’ll disable Data Exchange offer on all Linux VMs and save your SCVMM.

Get-VM * | where {$_.OperatingSystem -notlike "*Windows*"} | Set-VM -EnableDataExchange $false

As you see, it just looks for non-Windows machines and disable their Data Exchange offer. Good luck!


Posted in Windows Powershell | No Comment | 8,400 views | 30/11/2011 23:33

I’m happy to announce you my last product called PoSH Server. It’s an IIS alternative.

Functionalities:
1. HTML and Powershell language support: You can use your HTML and Powershell codes.
2. CSS, JS, XML and Flash support: Your HTML websites are fully supported.
3. Mime Type support: You can add new mime types to support new content types.
4. Default Document support: You can choose a default document for your website.
5. IIS like logging options: Daily and Hourly log rotation and advanced logging fileds. (Supported fileds: date time s-sitename s-computername s-ip cs-method cs-uri-stem s-port c-ip cs-version cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status)
6. Authentication support: Basic and Windows authentication
7. Log hashing: Signs log files and stores date and hash files

Download:

Donate:
Thanks to support this open source project!





Usage:

1. First, you should allow signed Powershell scripts:

Set-ExecutionPolicy AllSigned

2. Extract file to any directory you want.

3. Import start.ps1 file:

. .\start.ps1

4. Start PoSH Server:

Start-PoSHServer

5. Follow to instructions.

Sample Web Site Preview:

Sample Log Output Preview:

It’s almost stable. I’ve added PHP 5.3.8 support but removed it due to unstable PHP performance. You can add PHP support if you need, that’s possible. It’s good to publish internal websites, should not be used for world wide website publishing. In large number of visitors, performance may be dramatically reduced.


Posted in Windows Powershell | No Comment | 5,858 views | 30/11/2011 20:57

You can’t run unsigned Powershell scripts on servers if execution policy is not set as “Unrestricted”. You need to sign your scripts to run without modifying security policies. If you are a software developer, signing your scripts makes you reliable publisher for users.

By providing assurance that software is produced and signed by a “known publisher”, the practice of code signing can increase customer trust and lead to increased conversions and downloads.

But wait, you can’t sign a Powershell script with a Web certificate. So basically 20$ certificate from AlphaSSL or similar won’t work. For Windows, you need to have Code Signing Certificate. I’ll talk about GlobalSign code signing certificate and code signing process.

If you are a individual developer (like me) you can go with that option. If you purchase individual developer certificate, you’ll get a certificate for your name (like Yusuf Ozturk). Let’s read it from GlobalSign:

Software Vendors and Organizations can digitally sign and timestamp the software they distribute over the Internet, ensuring that the end user knows the software is legitimate and has not been tampered with since being published.

Individual Developers, i.e. those developers not associated with larger organizations, can also buy and use Code Signing certificates. The full name of the developer is attached to the certificate, so customers will see the message “This software has been published by John Doe”.

So what you need to get a code signing certificate?



Posted in Virtual Machine Manager, Windows Powershell | No Comment | 7,666 views | 29/11/2011 22:54

You may get this error when you try to start maintenance mode on a Hyper-V host.

Error (10434)
No suitable host is available for migrating the existing highly available virtual machines.

Recommended Action
Either improve the host ratings for the other hosts within the same cluster, and then try the operation again, or do not migrate the virtual machines.

SCVMM can not live migrate virtual machines if a shared ISO file is attached. So that can pause maintenance mode if you choose live migration mode.
You can execute following Powershell codes to find VMs which have shared ISO files.

Get-VM | Get-VirtualDVDDrive | where {$_.ISO -ne $null} | ft Name

If you’re looking for a specific Hyper-V host called Host01:

Get-VMHost Host01 | Get-VM | Get-VirtualDVDDrive | where {$_.ISO -ne $null} | ft Name

Deattach shared ISO files from VMs and start maintenance mode again.