Connect and disconnect Windows PowerShell to the Service (Live@edu Office 365)

Connect

PS> $LiveCred = Get-Credential

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

PS> Import-PSSession $Session

Disconnect

PS> Remove-PSSession

PS> Remove-PSSession $Session

Powershell Get-QADUser extracts Name and Email from an active directory OU organization unit

PS> Get-QADUser -SearchRoot “simonalsa.com/Users/PowerUsers” -SearchScope Subtree | select Name, Email

The value of SearchScope can be:

  ‘Base’     Limits the search to the base (SearchRoot) object. The result contains a maximum of one object.
  ‘OneLevel’ Searches the immediate child objects of the base (SearchRoot) object, excluding the base object.
  ‘Subtree’  Searches the whole sub-tree, including the base (SearchRoot) object and all its child objects.

Check the Domain OU list with

PS> Get-QADObject -Type OrganizationalUnit

How To manage Office 365 / Live edu Security Groups and Users usign Powershell

Make a new Security Group

PS C:\> New-DistributionGroup -Name WL-Test -Type Security

Assign User to the Security Group

PS C:\> Add-DistributionGroupMember -Identity WL-Test -Member id@simonalsa.com

Remove User from the Security Group

PS C:\> Remove-DistributionGroupMember -Identity WL-Test -Member id@simonalsa.com

Remove Security Group from AD

PS C:\> Remove-DistributionGroup -Identity WL-Test

Extract all AD users account from an Organizational Unit and remove them from a AD Group

Preload Powershell Quest AD Tools

set-Location c:\
Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-PSsnapin
Set-QADPSSnapinSettings -DefaultSizeLimit 0
Get-Command Get-QAD*

Extract all AD users account from an Organizational Unit and Save the target in a Powershell variable

$Ou = "Ou=Users,dc=simonalsa,dc=com"
$Target = Get-QADUser -searchroot $Ou | select SamAccountName

For each AD user remove them from the AD Group

remove-QADGroupMember PowerGroup SIMONALSA\User

Try and debug this lines for your purposes to automate the process

$Ou = "Ou=Users,dc=simonalsa,dc=com"
$Target = Get-QADUser -searchroot $Ou -searchScope 'OneLevel'
foreach ($Person in $Target) 
{
	remove-QADGroupMember -identity "CN=PoweGroup,$Ou" -member $Person.dn
}

Filesystem, MySQL and Crontab Backup application system

I have used two proffesional scripts for backup the application filesystem and database.

Filesystem

# (c) 2001 Chris Arrowood (GNU LGPL V2.1)
# You may view the full copyright text at:
# <a href="http://www.opensource.org/licenses/lgpl-license.html">http://www.opensource.org/licenses/lgpl-license.html</a>
# <a href="http://simplebashbu.sourceforge.net/">http://simplebashbu.sourceforge.net/</a>
# DESCRIPTION:
# A simple BASH script to do nightly backups to tarballs
# on a hard drive (not to tape)  Ideal for home linux users
# to easily backup thier system, provided they have an extra
# hard drive.
#

Basic configuration:

###############################################
#              User Variables                 #
###############################################
#
# Modify these variables to suit your needs
#
# Which day of the week do we want to do full backups? 0=Sunday
  LEVEL0DAY=0
# Where to create the backups; It should already exist
  BACKUP_DIR=/backup/fs
# Filesystems to backup seperated by spaces and the entire string in double quotes; each must start with /
  FILESYSTEMS="/var/www/www.simonalsa.com"
# Should we email results? Also should we email critical errors?  0=false, 1=true
  EMAIL=1
# EMAIL address to send results to
  EMAILADDRESS=simonalsa@simonalsa.com
# Email Subject
  EMAILSUBJECT="$HOSTNAME www.simonalsa.com Filesystem Backup"
# Only keep last weeks level0 backup (0) or keep all lvl 0 backups (1).  Keeping all data may take a lot of space!
  KEEPALL=0
# Do we wnat to compress the backup file using gzip? 0=false, 1=true
  COMPRESS=1
# Should we compress the log file when we are done?  0=false, 1=true
  COMPRESSLOG=1
# If we are compressing, what level do we use?
  COMPRESSLEVEL=6
# Determines whether we see all output to screen. It will still go to log regardless of this value.   0=false, 1=true
  QUIET=1
# Would you like to get detailed information from tar and gzip? 0=false, 1=true  
  VERBOSE=1

Script: backup_www.simonalsa.com.sh

Database 

# MySQL Backup Script
# VER. 2.5.1 - <a href="http://sourceforge.net/projects/automysqlbackup/">http://sourceforge.net/projects/automysqlbackup/</a>
# Copyright (c) 2002-2003 wipe_out@lycos.co.uk
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
Script: <a href="http://www.simonalsa.com/wp-content/uploads/2011/05/backup_mysql.simonalsa.com_.zip">backup_mysql.simonalsa.com</a>

Basic configuration:

 
### START CFG ###
 # Username to access the MySQL server e.g. dbuser
 USERNAME=dbo
 
 # Password to access the MySQL server e.g. password
 PASSWORD=
 
 # Host name (or IP address) of MySQL server e.g localhost
 DBHOST=db.simonalsa.com
 
 # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
 DBNAMES="db"
 
 # Backup directory location e.g /backups
 BACKUPDIR="/backup/db"
 
 # Mail setup
 # What would you like to be mailed to you?
 # - log   : send only log file
 # - files : send log file and sql files as attachments (see docs)
 # - stdout : will simply output the log to the screen if run manually.
 # - quiet : Only send logs if an error occurs to the MAILADDR.
 MAILCONTENT="log"
 
 # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])
 MAXATTSIZE="4000"
 
 # Email Address to send mail to? (<a href="mailto:user@domain.com">user@domain.com</a>)
 MAILADDR="simonalsa@simonalsa.com"

Crontab

File: crontab_backup

Content:

1 1 * * * /script/backup_www.simonalsa.com.sh
30 1 * * * /script/backup_mysql.simonalsa.com.sh

Upload a Hyper-V VM image using the VM Role of Windows Azure Platform (csupload.exe)

Once you have installed the Windows Azure SDK execute from the command line

cmd> csupload Add-VMImage -LiteralPath “F:\AZURE\box-machine\box-machine.vhd” -Location “West Europe”

Authentication across Windows Azure (csupload.exe)

You must have installed Windows Azure SDK.

From the command line execute

cmd>  csupload Set-Connection “SubscriptionId=XXXXXXXXX;CertificateThumbprint=YYYYYYYYYYYYY”

Where X is the ID of your Windows Azure Subscription and Y the Thumbprint of your personal certificate. Firstly the certificate must be uploaded to the Windows Azure Platform.

Make management certificate for Windows Azure Platform (makecert.exe)

Actually, you must install the .NET Framework (4) and the Windows SDK (Tools Option) to use makecert from the command line of your box.

For example
cmd> makecert -sky exchange -r -n “CN=box-machine” -pe -a sha1 -len 2048 -ss My “box-machine.cer”

If you wanna known more makecert option check Certificate Creation Tool (Makecert.exe) from the Microsoft MSDN.

Add a new column to a MySQL table alter add after

SQL Syntax> alter table tablename add column columnname varchar(10) after lastcolumnname

Where:

tablename is the table which is going to be modified.

columnname is the new column which is going to be added.

lastcolumnname is the position which the new column is going to be placed

Reference manual: http://dev.mysql.com/doc/refman/5.0/en/alter-table.html 



WordPress Themes