Category Archives: Scripts

Vim Cheat Sheet

i = Insert mode
o = instert new line
h = left
j = Move down
k = Move up
l =right
r = replace current character
x = remove a current character
dd = delete line
dw = delete Word
wq = Write and Quit Vim
q! = Quit with out saving

To search
/searchterm and press enter and then press N to next occurrence,

Copy and Pasting lines in VIM

  1. Make sure you’re in the normal mode. Press Esc to be sure. Then copy the entire line by pressing yy (more info :help yy). Y stands for “yank“. Instead, you can also press Y (shift + y) but I find the former a bit more convenient.
  2. Paste the line by pressing p. That will put the yanked line right under your cursor (on the next line). You can also paste before your current line by pressing the capital letter P. Again, to get some help you can use :help p.

Copy and Pasting in VIM

  1. Position the cursor where you want to begin cutting.
  2. Press v to select characters (or uppercase V to select whole lines, or Ctrl-v to select rectangular blocks).
  3. Move the cursor to the end of what you want to cut.
  4. Press d to cut (or y to copy).
  5. Move to where you would like to paste.
  6. Press P to paste before the cursor, or p to paste after.

 

Add New Disks in Ubuntu

#This Docs describes how to attached a new HD in linux this is blog is design to works with Ubuntu.

#Display all attched DISK
sudo lshw -class disk
#Show all attched HD
sudo fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003fa82

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 121634815 60816384 83 Linux
/dev/sda2 121636862 125827071 2095105 5 Extended
/dev/sda5 121636864 125827071 2095104 82 Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
213 heads, 34 sectors/track, 5791 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x36e7606e

Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux

Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

### Initiate fdisk to partition the disk:

sudo fdisk /dev/sdb

# Select n to a add a new partition
# Select 1 to a add it as primary partition

#Format it as ext3

sudo mkfs -t ext3 /dev/sdb1

##Monut the New Disk

#Create a direcory

sudo mkdir /media/mynewdrive

#Mount into manually:

sudo mount /dev/sdb1 /media/mynewdrive

#Unmount into manually:

sudo mount /dev/sdb1 /media/mynewdrive

#Automatic Mount At Boot

sudo nano -Bw /etc/fstab

#add this line

/dev/sdb1 /media/backupdrive ext4 defaults 0 2

PowerShell Script to Create new users in Active Directory

This scripts create users in active directory by look for the details listed in a CSV file which can be download here, and add a proxy email address, add to AD Groups and place them in a OU called temp OU.

You will need to change a number of values to match you environment:

  • @emaildomain.co.uk
  • OU=TempOU,DC=domain,DC=local
  • Name of the groups you would like them to be added to

If I had more time I would add in variable so you can easily change the value (may be in the future)


$csv_info = import-csv "C:\PSScripts\newusers.csv"
foreach ($line in $csv_info) 
{
    $name = $line.GivenName + " " + $line.Surname
    $samaccountname = $line.GivenName + "." + $Line.surname
    $emailaddress1 = $samaccountname + "@emaildomain.co.uk"
    $emailaddress = $emailaddress1.ToLower()
    $GROUP1 = $line.GROUP1
    $GROUP2 = $line.GROUP2
    write-host $name
    write-host $samaccountname
    write-host $emailaddress
    New-ADUser -GivenName $line.GivenName -Surname $line.Surname -Name $name -DisplayName $Name -UserPrincipalName $emailaddress -SamAccountName $SamAccountName -EmailAddress $emailaddress -Enabled $True -AccountPassword (ConvertTo-SecureString $line.Password -AsPlainText -force) -path 'OU=TempOU,DC=domain,DC=local'
    Set-ADUser $samaccountname -add @{ProxyAddresses="SMTP:$emailaddress"}
 
  If($GROUP1 -eq "YES")
 {
   Add-ADGroupMember -Identity "GROUP1" -Member $samaccountname
   write-host "Added to GROUP1"
 }

 If($GROUP2 -eq "YES")
 {
   Add-ADGroupMember -Identity "GROUP2" -Member $samaccountname
   write-host "Added to GROUP2"
 }
 
}

PowerShell Script to Assign License in Office365

Use the following script to Assign License in Office365

First connect to Office 365 via PowerShell


Get-MsolSubscription

This list the current license available in Office 365.


Set-MsolUser -UserPrincipalName username@office365domain.co.uk -UsageLocation UK

You first need to set the users to their local location in my case UK


Set-MsolUserLicense -UserPrincipalName username@office365domain.co.uk –AddLicenses “OFFICE365DOMAIN:O365_BUSINESS_ESSENTIALS”

This command assigns the licesnes you will need