Powershell : Useful Commands

Get members of a group:

get-adgroupmember -identity <GROUPNAME>

Get a list of user’s “PasswordLastSet” field has a date greater than 31/01/2000 along with their usernames and email addresses:

get-aduser -filter * -Properties PasswordLastSet | where {$_.passwordLastSet -ge [DateTime] "01/31/2000 00:01 AM"} | Select-Object Name, PasswordLastSet, SamAccountName, EmailAddress

Compare two CSV files for differences:

$refCSV = import-csv .\Source.csv 
$compCSV = import-csv .\Reference.csv 
compare-object -referenceobject $refCSV -DifferenceObject $compCSV | foreach { $_.InputObject}

Iterate over a text file of usernames (one per line) and query AD for some values, printing the useraccount’s containing OU in a easily readable form and output to results.csv:

$usersaffected = "c:\tmp\listofusernames.txt"
$output = foreach ($line in get-content $usersaffected) {get-aduser $line -Properties * | Select @{l='OU';e={$_.DistinguishedName.split(',')[1].split('=')[1]}},"whenCreated", "emailaddress", "passwordLastSet", "distinguishedName"}
$output | export-csv -path c:\tmp\results.csv

Create El Capitan 10.11 USB Installer Disk

  1. Download the installer from the App Store but do not install it, close the installer when it launches
  2. Format an 8GB+ USB Drive in the GUID type and Journaled (not case sensitive) partition
  3. run the command (where Untitled is the name of the partition you created in step 1):
    sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app --nointeraction
  4. Sit back and relax, smoke a pipe while you wait maybe

django setup with virtualenv & PyCharm

Setting up my django development (basic).

The following steps assuming that Python is installed.

  1. Setup a repository on Bitbucket:
    Ensure my development machine has access via SSH keys
  2. Install pip on development machine:
    https://pip.pypa.io/en/stable/installing.html:
    To install pip, securely download get-pip.py
    Then run the following (which may require administrator access):

    $[sudo] python get-pip.py
  3. Install virtualenv on the development machine:
    https://virtualenv.pypa.io/en/latest/installation.html

    $ [sudo] pip install virtualenv
  4. Create a working directory for the project:
    $mkdir /path/to/project/root
  5. Create the virtual environment to work from:
    $virtualenv /path/to/project/root/env
  6. Activate the virtual environment:
    $source /path/to/project/root/env/bin/activate
  7. Install mysql-python:
    (env)$[sudo]apt-get install python-dev libmysqlclient-dev
    
    (env)$pip install MySQL-python
  8. Install django 1.7:
    (env)$pip install django==1.7

    exit the virtualenv for now by:

    (env)$ deactivate
  9. Install pycharm to manage the project from a GUI:
    First install java:

    $ sudo add-apt-repository ppa:webupd8team/java
    $ sudo apt-get update
    $ sudo apt-get install oracle-java8-installer
    $ sudo apt-get install oracle-java8-set-default

    Next install pycharm:

    Download from https://www.jetbrains.com/pycharm/download/
    or from a directory outside of your project directory:

    $ wget http://download.jetbrains.com/python/pycharm-community-4.5.3.tar.gz

    change to that directory and :

    $ tar -xvf pycharm-community-4.5.3.tar.gz

    now to launch pycharm:

    $ ./pycharm-community-4.5.3/bin/pycharm.sh

 

Django 1.7, mysql-python and the pycharm editor should now be ready to use!

 

Next: Setting up the itstock django project http://www.davegernon.co.uk/techblog/initial-django-setup-for-itstock-project/