PowerShell Basics

by tscho | 18 May 2013 | 13:23

In the last view days I had to deal a lot with Windows PowerShell. I think it is hard to find a good starters guide, so here I go to fix this.

 

Get-Command: With this command you can display all available PowerShell-Cmdlets and PowerShell-Functions.

get-command

Get-Command -Module ModulName: For example with “Get-Command -Module Hyper-V” you get a list with all available commands from the Hyper-V module.

get-command -module

Get-Help: To lern more about a command simply type “Get-Help Command e. g. Get-Help Stop-VM”, this will show you the name, its syntax and if available an alias.

get-help

If you know Perl you also know the basics for PowerShell programming. This is how a variable could look like $VMList = Get-VM. If you type now echo $VMList you will get a lot of informations. If you only want to know what’s the state of your VM is you can do this with the following script.

$VMList = Get-VM

$VMName = ‘TheNameofyourVM’

$VMState = ($VMList | Where-Object {$_.Name -eq $VMName}).State

As you can see you can’t do a simple grep, you have to do this with the “Where-Object” command. The “.State” indicates the value  from the object state. It’s important that you use the brackets, otherwise it doesn’t work.

My Nerd Tattoo

by tscho | 23 April 2013 | 17:14

My Nerd Tattoo

Using a Raspberry Pi for the Monitoring Dashboard

by tscho | 01 April 2013 | 11:49

After successfully implementing Icinga there was just one step to perfection, a huge screen or projector displaying the errors and hosts that are down.

Because in our office there is no place for a projector we decided to buy a TV. There are two more advantages you get with a TV: On all this new devices you get HDMI and powered USB-ports. So there came along the idea to use a Raspberry Pi B to display the content.

How to install:

  • Do a standard installation “wheezy” image
  • Install Chromium because it got the nicest font rendering
  • Add Chromium to the autostart and disable the “restore last session” popup in case of power loss

Install the following Packages

sudo apt-get update && apt-get upgrade -y sudo

apt-get install chromium x11-xserver-utils unclutter

Add the following lines in the  /etc/xdg/lxsession/LXDE/autostart

vi /etc/xdg/lxsession/LXDE/autostart sed -i ‘s/”exited_cleanly”: false/”exited_cleanly”: true/’ ~/.config/chromium/Default/Preferences @chromium –kiosk –incognito http://yourpage.whatever

I used this Dashboard which was coded at first for Nagios

Die Sache mit den interbetriebsystemlichen Terminals

by wnetoa | 23 May 2012 | 21:22

man nehme:

  • 2 beliebige Hosts (hostA & hostB)
  • 2 moeglichst verschiedene OS’en (Fedora Core 15* & FreeBSD 9.0*)
  • einen shell access (mit screen gewürzt)
  • jede Menge Mut und
  • wahlweise sowie optional 1/8 Butter ;)
* mit diesen OS’en ist das Thema aufgefallen – andere Kombinationen nicht ausgeschlossen

Wenn man nun von hostA nach hostB eine ssh Session öffnet, so ist das weiter keine Zauberei und funktioniert im Allgemeinen recht problemlos.

Wie ich aber unlängst feststellen musste, ändert sich die Sachlage, wenn man aus einer auf Linux laufenden Screen-Session heraus auf ein FreeBSD System connecten will.  Die dann erscheinende Fehlermeldung ist mindestens genauso irreführend, wie jene beim Versuch per vim eine Datei bearbeiten zu wollen:

[23:26 root@hostA /root ]# echo $TERM
screen.linux
[23:26 root@hostA /root ]#ssh hostB
Last login: Tue May 22 21:55:34 2012 from hostA...

ycsh: Cannot open /etc/termcap.
csh: using dumb terminal settings.
hostB#
hostB#
hostB# vi .profile
vi: No terminal database found
hostB#
hostB#
hostB# exit
logout
Connection to hostB closed.
[00:20 root@hostA /root ]#

[23:57 root@hostA /root ]# echo $TERM
screen.linux
[23:57 root@hostA /root ]# TERM=vt100
[23:57 root@hostA /root ]# echo $TERM
vt100
[23:57 root@hostA /root ]# ssh hostB
Last login: Tue May 22 23:26:18 2012 from hostA...

hostB#
hostB# vi .profile

...working vim editing finally...

Ausserhalb dieser Screen Session stellt sich das Problem erst garnicht, da die TERM-Variable dann auf xterm-color gesetzt ist, wofür es am Zielsystem einen Capture gab.

Nach langem Gezeter bin ich dann zum Weg des geringsten Widerstandes übergegangen und hab schlicht in der Screen-Session vor dem Verbinden ein TERM=vt100 gesetzt; damit fühlen sich alle Beteiligten wieder verstanden und das ungehinderte Arbeiten auf der remote CLI kann losgehen.

Create a iSCSI target on FreeBSD with ZFS

by tscho | 16 February 2012 | 22:08

The easiest way using ZFS for a Share is to create an iSCSI target. With iSCSI you can have all the ZFS advantages in Windows. In this post I will show you how to create it on FreeBSD and use it in Windows.

At first you have to create a ZFS block device for the LUN. This is needed because iSCSI is accessing the disk block based.

zfs create -V 3T tank/backup

For exporting this filesystem via iSCSi you have to install istgt from ports. At first you should update your ports collection and then run the installation.

portsnap fetch && portsnap update

cd /usr/ports/net/istgt

make install clean

After the installation successfully finished you have to create the config files and edit them. You actually don’t have to create them, you can simply copy the samples.

cd /usr/local/etc/istgt/

cp auth.conf.sample auth.conf

cp istgt.conf.sample istgt.conf

cp istgtcontrol.conf.sample istgtcontrol.conf

Now change your servers IP address and the path to the created ZFS in the istgt.conf

[PortalGroup1]

Portal DA1 192.168.10.1:3269 <= Change to your IP

[InitiatorGroup1]

Netmask 10.101.230.16/24 <= Change to your IP and Netmask

[LogicalUnit0]

LUN0 Storage /dev/zvol/tank/bankup

Finally lets start the is daemon

/usr/local/etc/rc.d/istgt start

If you are using Windows Server 2003 you have to install first the iSCSI Initiator.