Powershell – Update Active Directory Users Profile Data

Here is a small snippet to bulk update an OU with user profile data. Recently used to fill in default values for AD.

Change the OU and Domain details to suit; Requires full LDAP path (e.g. YOURDOMAIN.LOCAL would be DC=YOURDOM,DC=LOCAL)

Import-Module ActiveDirectory 
$Users = Get-ADUser -Filter * -SearchBase "OU=Users,DC=YOURDOM,DC=LOCAL"

foreach($User in $Users) {
    # Update properties.
    $User.postalAddress = "Address Line 1"
	$User.street = "Address Line 2"
	$User.telephoneNumber = "00000 00000000"
	$User.department = "Your Department"
	$User.wWWHomePage = "www.website.com"
	$User.postOfficeBox = "England"
	$User.city = "City"
	$User.state = "County"
	$User.postalCode = "Post Code"
    Set-ADUser -Instance $User

Always be careful bulk updating users via script. More profile values can be found in the Advanced Attribute Editor in the Active Directory Snap-In.

Posted in Powershell | Tagged , , , | Leave a comment

Powershell – Export All Email Addresses from Office 365 Exchange Online

See below to export all E-Mail addresses from Office 365 Exchange Online. If you have never connected to Powershell before then you need to download the Office 365 Powershell Cmdlets from Microsoft.

Connecting to Powershell is easy: Installing Windows PowerShell cmdlets only sets the stage.

This does nothing for actually connecting them to the Microsoft Office 365 cloud. Connecting to the cloud requires a cumbersome—but straightforward—five-step process:

1. Import your newly installed Online Services module
2. Enter Office 365 credentials
3. Create a remote session
4. Import that session’s commands into your local Windows PowerShell session
5. Connect to Office 365 services After installing the Cmdlets, open up Powershell and type the following:

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection

This will prompt for a login username and password; use your administrator login for Office 365. You next need to import the session:

Import-PSSession $session

This should connect you to Powershell. If you cannot execute commands you need to set the execution policy to Remote-Signed, as below:

Set-ExecutionPolicy RemoteSigned

After this is done you’ll be able to run your command to export data. Running the following snippet will export ALL email addresses in your organization to a CSV file called addresses.csv.

Get-Recipient -ResultSize Unlimited | select DisplayName,RecipientType,EmailAddresses | Export-Csv addresses.csv

Have fun.

Posted in Blog, Powershell | Leave a comment

PHP – Read CSV Data into PHP Array

First post for a while! The website will be updated more regularly now though. Here is a quick PHP snippet that will read CSV data from a file specified and return a Multidimensional Array with keys based on column names.

	private function __readCSV($fileName) {
			$file = fopen($fileName, 'r'); 
			$fields = array();
			$CSVdata = array();
			if ($file) {
				while (($data = fgetcsv($file)) !== false) {
					if(empty($fields)) {
						$fields = $data;

					$row = array_combine($fields, $data);
					$CSVdata[] = $row;
				unset($file, $row, $data, $fields);
				return $CSVdata;

Just call the function with the full path to the file. Any questions then leave a comment below. Enjoy.

Posted in PHP | Tagged , , , | Leave a comment

PHP – Custom MVC Framework with Smarty3 and ActiveRecords

After using a few different PHP MVC’s I decided to work on my own framework when I had some spare time. Over the past few days I’ve put together a lightweight and feature rich small PHP MVC Framework. Note that it should currently be considered beta software, It should be useful for anyone wanting to develop their own MVC framework, feel free to use this as a base for your own framework or projects.

Continue reading

Posted in PHP, PHP frameworks | Tagged , , | 4 Comments

PHP – Using the Steam XML API

Steam has had XML output on profiles, games and groups for a while so I thought I would post up one of my old classes for retrieving Steam user data. The class below will download the XML for games and a user profile(s) and return back an array to work with.

Continue reading

Posted in PHP | Tagged , , , | 2 Comments

PHP – Easy AES Encryption Class

AES Encryption is now an easy way of securing your data with a secret key thanks to the MCrypt PHP extension. You can read documentation and basic examples on using MCrypt on the PHP.net page. Below is a small class I have put together to take advantage of encrypting/decrypting data and returning it in a Base64 format so it can be stored safely in a database.

Continue reading

Posted in PHP | Tagged , , , | Leave a comment

PHP – TinyMVC Session Plugin

Another TinyMVC plugin; this time to get and set session variables from within your controllers. Utilising PHP5′s magic functions to add and remove entries from the $_SESSION global, quickly and easily. Drop the following code into your plug-ins directory and load it up.

Continue reading

Posted in PHP, PHP frameworks | Tagged , , , | 1 Comment

PHP – Useful TinyMVC View Helpers

Back again with more TinyMVC code. As I get more into this framework the more code I’ll be posting up, the functions in the code below are to be used directly from TinyMVC views and not controllers or models.

One of the most useful features below is block($view) allowing you to directly output other views, inside your view (like CakePHP does) although this is technically not following “strict” MVC guidelines it is still a very useful feature.

Continue reading

Posted in PHP, PHP frameworks | Tagged , , , | 2 Comments