Wednesday 23 November 2016

Notepad++ Extended Find and Replace

This tip is actually from Superuser.com - its a handy hint I have used many times to reformat large amounts of user data from various systems into a format I can then utilise universally - so I have published it here for reference:


Consider the scenario where you have a specific string that you want to find-and-replace. You want to replace it with a new string that contains a newline character (or character sequence).
abc123 xyz456-blah
fsafd23 xyz456-green
89hjkf23 xyz456-red
afdsa23 xyz456-yellow
abaac123 xyz456-orange
In the scenario above, I'd like to find " xyz" and replace the space with a carriage return/newline.
The results would look like:
abc123
xyz456-blah
fsafd23
xyz456-green
89hjkf23
xyz456-red

Search string:
 xyz
Note the space in front of xyz.
Replace string:
\r\nxyz
You will also need to set the "Search Mode" to "Extended" so that Notepad++ honors escape codes.

Thursday 10 March 2016

Powershell to log into Gmail

I'm automating some tasks, one of which involves invoking a browser and signing into gmail. I wrestled with problems for an hour or so till I realised my tag name for the final submit was actually "input".  I've pasted the currently working script below in case it can be of use.


# Create New IE Object in visible browser window
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true

# Open URL
$ie.Navigate("mail.google.com") 

# Let page load
while ($ie.Busy -eq $true){Start-Sleep -seconds 4;}

# Enter username / email address
$usernamefield = $ie.Document.getElementByID('Email')
$usernamefield.value = 'your-email-here@gmail.com'

# CLICK "Next" button
$next=$ie.Document.getElementByID('next')
$next.click()

# Enter password
$passwordfield = $ie.Document.getElementByID('Passwd-hidden')
$passwordfield.value = 'your-password-here'

# Click the "Sign In" Button
# ELEMENT: 
# THEREFORE the tag name of your button is "input" and the type is "submit"
$signIn = $ie.Document.getElementsByTagName("input") | where-object {$_.type -eq "submit"}
$signIn.click();

Sunday 21 February 2016

Powershell Through A Proxy

If you've ever been stuck in that situation where you need to scrape web pages or need other internet functions from behind a proxy...

Utilise the same proxy as IE:
netsh winhttp import proxy source=ie
If your proxy requires credentials:
$webclient=New-Object System.Net.WebClient
$creds=Get-Credential
$webclient.Proxy.Credentials=$creds