Tuesday, December 15, 2015

Everyday Powershell - Part 36 - Check-EliteDangerous

So as this is typed the game Elite Dangerous is being patched to version 1.5 when the patch is done we'll be able to land our ships on planets!!! PLANETS!

We're all pretty excited by this and want to know as soon as the game is ready to play again. Well here's where powershell can help!

$issuesstring = (ConvertFrom-Json (invoke-webrequest http://hosting.zaonce.net/launcher-status/status.json).content).text
while ((ConvertFrom-Json (invoke-webrequest http://hosting.zaonce.net/launcher-status/status.json).content).text -eq $issuesstring){
    Write-host ((get-date).tostring() + " " + $issuesstring)
    Start-Sleep -Seconds 300
Write-Warning "We're on!"
[Reflection.Assembly]::LoadWithPartialName('System.Speech'| Out-Null
(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak("Go get em commander!")

Simple loop that'll tell you when then status changes.

Tuesday, November 24, 2015

Everyday Powershell - Part 35 - Check for eDellRoot certificate

So Dell, bless their wee hearts, have been shipping their own root cert with new laptops. Problem is the private key is available to everyone who's got a copy of this cert! Which means any halfwit could sign ANYTHING and if this cert is in your root certs that halfwits stuff is going to be trusted on your computer.

Better check if that cert is there;
Get-ChildItem -path cert:\LocalMachine\root | where Thumbprint -eq 02c2d931062d7b1dc2a5c7f5f0685064081fb221
Get-ChildItem -path cert:\LocalMachine\root | where Thumbprint -eq 98a04e4163357790c4a79e6d713ff0af51fe6927

There's two of them, check for both. If they're there just delete them. It might break some of the Dell bloatware that ships with the laptops. But better to live without bloatware than have some dodgy root cert that every man and his dog has the private key for.

Sunday, September 13, 2015

Everyday Powershell - Part 34 - Browse the internet in private

Everyday Powershell. Getting you into the shell by providing little doses of utility that you could use everyday!

Does your Countries Government spy on it's citizens internet activity?

Do you think that's maybe a bit of a overreach?

Lot's of other people think that too!

One of the things the technically minded of us do to keep prying eyes from our private lives is run VPNs. If you've setup a VPN and have a dialler in windows you want to trigger you can use this script to fire up the VPN then kick off Chrome in Incognito Mode.

$connections = rasdial.exe
if ($connections -contains "No Connections"){

Start-Process "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -ArgumentList "-incognito"

#Create a desktop Shortcut with this;
#C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& 'c:\scripts\dial-vpn.ps1'"

Wednesday, August 12, 2015

Everyday Powershell - Part 33 - New-RandomPassword

Everyday Powershell returns! This series is about providing easily digestible chucks of powershell goodness so those of us new to the world or the shell can start leveraging the awesome power of the shell!

If you are the kind of person who creates a lot of accounts for any reason you know the value of having a password randomiser handy.

function new-randompassword{
        [int]$length = 25

    $possiblecharacters = "1","2","3","4","5","6","7","8","9","0","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","Q","R","S","T","U","V","W","Y","X","Z"
    $password = ""
    $i = 0
    While($i -le $length){
        $password += get-random -InputObject $possiblecharacters

Really straight forward and easy to understand function here with one parameter -length. Easily extended to support more characters. You could even remove possible similar looking characters from the list 1, I, l  kind look the same as do 0,O and o. It's all up to you! That's the great thing with writing your own functions. If you don't like what it does you can just change it right there and make it do what you want!

Have a great day Powershellers!

Tuesday, May 5, 2015

40,000 Page Views

Looks like we just clocked over 40,000 page views!

Never really expected anyone to to read this blog when it started and it's really gratifying to know that what we're putting out there is helping people at least some of the time.

So a big thanks to all the Readers, Robots, Bots, Crawlers, Advertisers oh and actual honest to goodness humans that are making our page views climb!

Friday, April 10, 2015

Everyday Powershell - Part 32 - Create-TaskbarPinnedShortcut

So you may have a need to pin things to taskbars... We Certainly do apparently clicking on the start menu is a step too far for some users... Long and boring story.

Anyway here's some powershell.

$itemstopin = "C:\Program Files (x86)\Microsoft Office\Office15\excel.exe",
"C:\Program Files (x86)\Microsoft Office\Office15\outlook.exe",
"C:\Program Files (x86)\Microsoft Office\Office15\winword.exe"

foreach($item in $itemstopin){
    $path = [system.io.path]::getdirectoryname($item)
    $app = [system.io.path]::getfilename($item)
    $shell = new-object -com "Shell.Application"
    $folder = $shell.Namespace($path
    $item = $folder.Parsename($app)
All credit goes to this post on stackoverflow http://stackoverflow.com/questions/9739772/how-to-pin-to-taskbar-using-powershell I look at that site and often wonder how many programmers there really are versus how many cut and paste from there.

SOMEONE is writing all this code that the rest of us are copying. Wonder what the ratio really is?

Friday, February 13, 2015

Everyday Powershell - Part 31 - Send email with multiple attachments

So back in Part 24 reader sivaramsharma asked if send-mailmessage could handle multiple attachments so we threw together this post...

$files = get-childitem C:\reports | where name -like "*.png"
$body = @()
$attachments = @()
foreach($file in $files){
    $filename = [system.io.path]::GetFileName($file.FullName)
    $attachments += $file.fullname
    $body += "TEST <br />
<img src='" + $filename + "'/>TEST <br />"
$body = $body | Out-String
Send-MailMessage -to someuser@someserver.com -From someotheruser@someserver.com -SmtpServer somemailserver -Subject "Test" -BodyAsHtml $body -Attachments $attachments

It's a neat little example of generating some HTML in a loop then sending it off using send-mailmessage.

Thursday, February 5, 2015

Everyday Powershell - Part 30 - Beware of reinventing the wheel

Hmmm bit of a funny one today... So I spent a few minutes writing this;

function get-recursegroupmembers{
    $users = @()
    $groups = get-adgroupmember $groupname
    foreach($object in $groups){
        if ($object.objectclass -eq "group"){
            get-recursegroupmembers $object
        if ($object.objectclass -eq "user"){
            $users += $object

When I realised that this would do just fine;
get-adgroupmember $group -Recursive

So yeah, lesson for the day is don't spend valuable time writing stuff when the problem has already been solved.