Office 365 PowerShell Snippets

Well, there exist dozens of Blog posts like “Howto connect PowerShell to Office 365″ etc. In this post I want to share those commands that I use frequently:

First, creating a connection to Office 365:

PS > $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
PS > Set-ExecutionPolicy -ExecutionPolicy unrestricted
PS > Import-PSSession $Session

Changing the principal name of a user:

PS > Set-MsolUserPrincipalName –UserPrincipalName user@example.onmicrosoft.com -newUserPrincipalName user@example.com

Set the passwords of all users to never expire:

PS > Get-MSOLUser | Set-MsolUser -PasswordNeverExpires $true

Add/Remove mailbox permissions:

PS > Add-MailboxPermission user@example.com -User admin@example.com -AccessRights FullAccess -InheritanceType All -AutoMapping $false
PS > Remove-MailboxPermission user@example.com -User admin@example.com -AccessRights FullAccess -InheritanceType All

Hide/Show a mailbox in the GAL:

PS > Set-Mailbox user@example.com -HiddenFromAddressListsEnabled $true

To be contd.

Accessing KeePass databases from PHP scripts

Always wanted to write an extension for PHP! :-) More precisely, an extension which allows PHP scripts to access KeePass databases. Today I finally found time to read some articles (here, here, and here) on PHP extension writing. I compiled PHP 5.x and KeePass 2., and started the project PHPpw, which is supposed to bring together these 2 worlds (PHP & KeePass). PHPpw (pw = password) is open source and available at SourceForge.net. The extension is a proof of concept and provides the following PHP functions:

  • keepass_open(): Opens a KeePass database. The first argument is the filename of the database; the second argument is the masterkey.
  • keepass_close(): Closes a previously opened KeePass database.
  • keepass_get_name(): Delivers the name of the root folder of the KeePass database.
1
2
3
4
5
if ( !keepass_open("test.kdbx", "test1234") ) die();
 
echo keepass_get_name();
 
keepass_close();

The project has several limitations, e.g., only one KeePass database can be used. Further, once a KeePass database is opened, it is accessible to all users. Anyway, check out the source code and feel free to join this project today!

Fehler bei der Synchronisierung einiger Löschungen

Das Zusammenspiel von Office 365 und Outlook 2010 funktioniert noch nicht 100%ig. Nach dem Löschen von Elementen in Outlook 2010 (Mails, Kontakte etc.) wird im Ordner Synchronisierungsprobleme (Sync Issues) die folgende Fehlermeldung erzeugt: Fehler bei der Synchronisierung einiger Löschungen. bzw. Synchronization of some deletions failed.

Die Synchronisierung selbst funktioniert fehlerfrei. Das Problem wird schon seit langer Zeit in verschiedenen Microsoft-Foren diskutiert, z.B. hier. Der Workaround, EnableConflictLogging in der Registry auf 0 zu setzen, funktioniert nicht. Immerhin bestätigte mir der Support von Office 365, dass der Fehler bekannt sei:

Bezüglich Ihrer Serviceanfrage 1157274502 habe ich folgende Informationen für Sie.
Das Problem mit der Outlook ist bei Design. Ich habe es selber getestet und ich bekomme die selben Fehlermeldungen wie Sie. Andere Kollegen von mir, bei reproduzieren, haben das gleichen Problem. Microsoft arbeitet an das Problem zu beseitigen. Wenn Sie möchten Sie können gerne die Abteilung, die sich mit Officepacket beschäftigen, zu kontaktieren.

Der einzig funktionierende Workaround ist also, bis zur Problembeseitigung Outlook 2007 einzusetzen. Dort tritt dieses Problem nämlich nicht auf.

Howto Resize a VirtualBox Disk (VDI)

In case you didn’t know: Finally VirtualBox version >= 4 can resize existing disks (i.e., VDI files). Just use the following VBoxManage command and provide your disk file (VDI) and the needed size in megabytes:

VBoxManage modifyhd YOUR_DISK.vdi --resize SIZE_IN_MB

Enumerating Child Windows in Silverlight

Today I’d like to give you a short example how to enumerate all child windows in a Silverlight application:

1
2
3
4
5
6
7
8
9
10
11
12
13
void EnumChildWindows(Visual visualParent)
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visualParent); i++)
    {
        Visual visual = (Visual)VisualTreeHelper.GetChild(visualParent, i);
        EnumChildWindows(visual);
 
        if (visual is Button)
        {
            // do something
        }
    }
}

In the code snippet above, the child windows are collected recursively. Since EnumChildWindows accepts a visualParent of Type Visual, one can start using the MainWindow object, e.g. obtained via reflection. This technique even finds child windows (buttons, text boxes, etc.) not defined in a XAML file.

T-Mobile MultiSIM SMS-Empfang

Dieser Post ist eigentlich nur eine Gedankenstütze für mich: :-)

  • Wie aktiviert man den SMS-Empfang bei einer MultiSIM von T-Mobile?
    Lösung: *222#
  • Wie fragt man den Status ab?
    Lösung: *221#

Quelle: http://www.t-mobile.de/T-D1/cds/td1_cds_popup/1,1132,108350-0-,00.html

OpenSSL: Create a self-signed Certificate

This post is just a sticky note, because for testing purposes I have to create a self-signed certificate from time to time.

openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

These commands have been taken from here.

OpenSSL: Convert & Merge Key with Certificate

This second sticky note describes how to (1) convert a P12 file to PEM, and how to (2) merge a PEM and a CRT file to P12.

# covert
openssl pkcs12 -nocerts -in key_in.p12 -out key.pem
 
# merge
openssl pkcs12 -export -inkey key.pem -in pki.crt -out key_out.p12

These commands have been taken from here.

Handling multiple Keyboards in MFC

If you want to handle more than one keyboard in your MFC application (e.g. a keyboard and a barcode scanner), you can make use of Win API’s raw input functionality. It allows to determine the associated keyboard of an occurred key press – just to highlight one interesting use case.

The first thing you have to do is the registration of the raw input devices by initializing the RAWINPUTDEVICE structure and calling the RegisterRawInputDevices method. A detailed description of the magic numbers in the listing below can be found here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
BOOL CApplication::InitInstance()
{
  // ...
 
  RAWINPUTDEVICE ltDevice;
  ltDevice.usUsagePage = 0x01;
  ltDevice.usUsage = 0x06;
  ltDevice.dwFlags = RIDEV_INPUTSINK;
  ltDevice.hwndTarget = AfxGetMainWnd()->GetSafeHwnd();
 
  if ( !RegisterRawInputDevices(&ltDevice, 1, sizeof(RAWINPUTDEVICE)) )
  {
    return FALSE;
  }
 
  // ...
}

Secondly, you have to implement the OnRawInput method of the related CWnd-based class. And, don’t forget to enable this event handler by inserting ON_WM_INPUT() in the message map. The following example illustrates how to extract the keyboard’s device name of a pressed key.

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
void CMainFrame::OnRawInput(UINT piInputCode, HRAWINPUT phRawInput)
{
  // only process foreground inputs
  if ( RIM_INPUT != piInputCode )
    return;
 
  // determine the size of the resulting RAWINPUTHEADER structure
  UINT liSize;
  if ( 0 != GetRawInputData(phRawInput, RID_INPUT, NULL, &liSize, sizeof(RAWINPUTHEADER)) )
    return;
 
  // determine the actual RAWINPUTHEADER structure
  LPBYTE lpbBuffer = new BYTE[liSize];
  if ( liSize != GetRawInputData(phRawInput, RID_INPUT, lpbBuffer, &liSize, sizeof(RAWINPUTHEADER)) )
    return;
 
  // determine the size of the resulting device name's string
  if ( 0 != GetRawInputDeviceInfo(((RAWINPUT*)lpbBuffer)->header.hDevice, RIDI_DEVICENAME, NULL, &liSize) )
    return;
 
  // determine the actual string of the device name
  TCHAR *lpszDeviceName = new TCHAR[liSize];
  if ( 0 > GetRawInputDeviceInfo(((RAWINPUT*)lpbBuffer)->header.hDevice, RIDI_DEVICENAME, lpszDeviceName, &liSize) )
    return;
 
  TRACE(_T("%s\n"), lpszDeviceName);
  delete [] lpbBuffer;
  delete [] lpszDeviceName;
}