Create Cisco VLAN Config with Powershell

Powershell HeaderSmall Script for creating a simple CISCO VLAN config.

# Create Cisco VLANs Config
#
# www.thomasmaurer.ch
# (c) 2010 Thomas Maurer
#
#

# First VLAN which should be created?
[int]$VLAN = 1201
# How many VLANs should be created?
[int]$VLANCount = 25
# Start IP Address
[int]$IP = 1
# Subnet
[string]$Subnetmaskv4 = "255.255.255.252"
[string]$Subnetmaskv6 = "64"
# Next IP (Its Important for Subnet)
[int]$AddtoIP = 4
# IPv4 Address Template
[string]$IPv4AddressTemplate = "192.168.1."
# IPv6 Address Template
[string]$IPv6AddressTemplate = "2002:1b50:251:22:192:168:1:"
# Config File Name
[String]$ConfigFile = "C:\Users\tm\Desktop\config.txt"

# Creats Config
for($counter = 0;$counter -le $VLANCount;$counter++) {
	[string]$interfaceconf = "interface Vlan" + $VLAN
	[string]$IPv4conf = "ip address " + $IPv4AddressTemplate + $IP + " " + $Subnetmaskv4
	[string]$IPv6conf = "ipv6 address " + $IPv6AddressTemplate + $IP + "/" + $Subnetmaskv6
	Add-Content $ConfigFile $interfaceconf
	Add-Content $ConfigFile "no shutdown"
	Add-Content $ConfigFile $IPv4conf
	Add-Content $ConfigFile $IPv6conf
	$IP = $IP + $AddtoIP
}

How to use Adium on every Mac OS X Space

Since Mac OS X Leopard I use Spaces a lot. In the System Preferences, Expose & Spaces you can configure Spaces. You can also configure Applications to use everytime the same Space. So for example my iCal always opens on Space 3, Tweetie always on Space 1 and so on. This is nothing new but it is pretty usefull to arrange your workspace like that.

Mac OS X Spaces

I also use Adium a lot so, often I copy past something form Safari, Evernote, Mail or another program to the Adium Message Window. But with Spaces I always had to drag the Adium Message Window to the Space of the Application or the other way round. But there is a pretty cool setting in Spaces. You can set an Application be on “Every Space”. So I set Adium to “Every Space” and I don’t have to move the Adium Message Window or a Application.

Mac OS X Spaces

I know this is nothing new, but I just didn’t know about this function.

Powershell: Create a new Sharepoint 2010 WebApplication and Site collection

Powershell Header

Microsoft Sharepoint 2010 is one of the new products which supports Windows Powershell commands. Its really easy to do the most tasks you do normally in the Sharepoint Central Administration with Powershell.

Microsoft created a Powershell Snapin for Sharepoint 2010, which is called “Microsoft.Sharepoint.Powershell”. This enables a lot of new Powershell cmdlets for Sharepoint.

With this small scripts you can simply create a new WebApplication and/or a new Sharepoint Site Collection.

Add the Sharepoint cmdlets:

Add-PsSnapin Microsoft.SharePoint.PowerShell

Help for creating a new Sharepoint WebApplication:

The Powershell command for creating a new Web Application is New-SPWebApplication.

Get-Help New-SPWebApplication
NAME
    New-SPWebApplication

SYNOPSIS
    Creates a new Web application within the local farm.

SYNTAX
    New-SPWebApplication -ApplicationPool <String> -Name <String> [-AdditionalClaimProvider <SPClaimProviderPipeBind[]>
    ] [-AllowAnonymousAccess <SwitchParameter>] [-ApplicationPoolAccount <SPProcessAccountPipeBind>] [-AssignmentCollec
    tion <SPAssignmentCollection>] [-AuthenticationMethod <String>] [-AuthenticationProvider <SPAuthenticationProviderP
    ipeBind[]>] [-Confirm [<SwitchParameter>]] [-DatabaseCredentials <PSCredential>] [-DatabaseName <String>] [-Databas
    eServer <String>] [-HostHeader <String>] [-Path <String>] [-Port <UInt32>] [-SecureSocketsLayer <SwitchParameter>]
    [-ServiceApplicationProxyGroup <SPServiceApplicationProxyGroupPipeBind>] [-SignInRedirectProvider <SPTrustedIdentit
    yTokenIssuerPipeBind>] [-SignInRedirectURL <String>] [-Url <String>] [-WhatIf [<SwitchParameter>]] [<CommonParamete
    rs>]

DESCRIPTION
    Creates a new Web application specified by the Name parameter. The user specified by the DatabaseCredentials parame
    ter must be a member of the dbcreator fixed server role on the database server.

    For permissions and the most current information about Windows PowerShell for SharePoint Products, see the online d
    ocumentation (http://go.microsoft.com/fwlink/?LinkId=163185).

RELATED LINKS
    Get-SPWebApplication
    Set-SPWebApplication
    Get-SPWebApplication

REMARKS
    To see the examples, type: "get-help New-SPWebApplication -examples".
    For more information, type: "get-help New-SPWebApplication -detailed".
    For technical information, type: "get-help New-SPWebApplication -full".

Creating a new Sharepoint WebApplication:

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Set variables
$WebAppName = "Contoso Sharepoint1"
$WebAppHostHeader = "sharepoint1.contoso.com"
$WebAppPort = 80
$WebAppAppPool = "SharePoint1AppPool"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "contoso\sp_serviceuser"
$WebAppDatabaseName = "Sharepoint1"
$WebAppDatabaseServer = "SQLServer\InstanceName"

# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WWebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer

Creating a new Sharepoint Site Collection:

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Templates
# Name                 Title                                    LocaleId   Custom
# ----                 -----                                    --------   ------
# GLOBAL#0             Global template                          1033       False
# STS#0                Team Site                                1033       False
# STS#1                Blank Site                               1033       False
# STS#2                Document Workspace                       1033       False
# MPS#0                Basic Meeting Workspace                  1033       False
# MPS#1                Blank Meeting Workspace                  1033       False
# MPS#2                Decision Meeting Workspace               1033       False
# MPS#3                Social Meeting Workspace                 1033       False
# MPS#4                Multipage Meeting Workspace              1033       False
# CENTRALADMIN#0       Central Admin Site                       1033       False
# WIKI#0               Wiki Site                                1033       False
# BLOG#0               Blog                                     1033       False
# SGS#0                Group Work Site                          1033       False
# TENANTADMIN#0        Tenant Admin Site                        1033       False

# Languages
# Name                	Title
# ----                	-----
# German				1031
# English				1033
# French				1036
# Spanish				1034

# Set variables
$SiteCollectionName = "Homepage"
$SiteCollectionURL = "http://sharepoint.contoso.com"
$SiteCollectionTemplate = "STS#0"
$SiteCollectionLanguage = 1033
$SiteCollectionOwner = "contoso\UserName"

# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName

Creating a new Sharepoint WebApplication and a Sharepoint Site Collection:

# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Set variables
$WebAppName = "Contoso Sharepoint1"
$WebAppHostHeader = "sharepoint1.contoso.com"
$WebAppPort = 80
$WebAppAppPool = "SharePoint1AppPool"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "contoso\sp_serviceuser"
$WebAppDatabaseName = "Sharepoint1"
$WebAppDatabaseServer = "SQLServer\InstanceName"
$SiteCollectionName = "Homepage"
$SiteCollectionURL = ("http://" + $WebAppHostHeader)
$SiteCollectionTemplate = "STS#0"
$SiteCollectionLanguage = 1033
$SiteCollectionOwner = "contoso\UserName"

# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer

# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName

Simple C++ rect2polar program @KTSI

This is another simple C++ program done for KTSI. This one converts rectangular to polar coordinates.

#include <iostream>
#include <cmath>

using namespace std;

void rect2polar(double &value, double &angle, double x, double y) {
    value = sqrt(pow(x, 2) + pow(y, 2));
    angle = 180 / M_PI * atan2(y,x);
}

int main(){
    double value;
    double angle;
    double x = 4;
    double y = 3;

    rect2polar(value, angle, x, y);

    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
    cout << "value = " << value << endl;
    cout << "angle = " << angle << endl;
    //system("PAUSE");
    return 0;
}

Simple C++ dec2bin program @KTSI

This is a very simple dec2bin program done for KTSI.

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

string dec2bin (int v) {
	if (v > 255) {
		return "";
	}
	else {
		string bin;
		int oneorzero;
		for(int i=8;i>0;i--) {
			oneorzero = v % 2;
			if (oneorzero == 1) {
				bin = "1" + bin;
			}
			else {
				bin = "0" + bin;
			}
			v /= 2;

		}

	return bin;

	}
}

int main(){
    int v;
    do {
        cout << "Wert(ende = -1) = ";
        if (!(cin >> v)) {
            return 0;
        }
        if (v < 0) break;
        string s = dec2bin(v);
        cout << s << endl;
        //system("PAUSE");
    } while(v >= 0);
    cout << "bye" << endl;
    //system("PAUSE");
    return 0;
}