Powershell if file does not exist

Small gotcha that caught me recently, I needed to do a test-path but action if a file did NOT exist, and I had trouble getting it to work first go, so I’m writing this here:

## check file exists
if (!(Test-Path $FileToCheck))
     throw "$FileToCheck not found"

This will throw the exception if the file can not be found.

Batch converting video combining FFMpeg and Powershell

I had a bunch of MKV files that I needed to convert to mp4.  I don’t have any fancy video editing software, and found that a program called ffmpeg exists, which is a command line tool that will do this.  Once I verified that it would do what I wanted, I decided to write a powershell script that will do the work for me, which you can find here.

You will need to download and install ffmpeg and run the script.  I have defaulted ffmpeg to “c:\program files\ffmpeg\ffmpeg.exe” as this seems like the logical place for me.

If you have any comments, or ideas on how to improve, please let me know in the comments below.

Disable Office 2016 typing animation

To disable the office 2016 typing animation, navigate to:


Create a new Key called Graphics

In the Graphics key, create a new DWORD 32 bit value for DisableAnimations

Set a value of 1.  Log out and back in and the animations should no longer be active.

Install netdata on C.H.I.P (or a raspberry PI)

Netdata details: https://github.com/firehol/netdata/wiki

C.H.I.P: http://anonit.blogspot.com.au/2016/08/installing-chip-headless.html; or
Raspberry PI:  http://anonit.blogspot.com.au/2016/05/headless-install-of-raspbian-jessie.html

Logon to the device using SSH.
Check if CURL is installed by using the command
which curl
if it is not installed then install using sudo apt-get install curl.
Install the full install packages for netdata:
curl -Ss ‘https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh’ >/tmp/kickstart.sh && bash /tmp/kickstart.sh -i netdata-all
(There is a minimum install package that can be used if necessary: curl -Ss ‘https://raw.githubusercontent.com/firehol/netdata-demo-site/master/install-required-packages.sh’ >/tmp/kickstart.sh && bash /tmp/kickstart.sh -i netdata)
Download the netdata installer:
git clone https://github.com/firehol/netdata.git –depth=1
go into the netdata folder:
cd netdata
install netdata:
sudo ./netdata-installer.sh
Once installed, you can access the website on %IPADDRESS%:19999
to update, go into the netdata folder:
cd netdata
and run the updater:
sudo ./netdata-updater.sh
references:  https://github.com/firehol/netdata/wiki/Installation

Installing Pi-hole on a C.H.I.P

Requirements: C.H.I.P configured as: http://anonit.blogspot.com.au/2016/08/installing-chip-headless.html, with a static IP address

Type the command
sudo cp /etc/resolv.conf resolv.conf.bak
sudo nano /etc/resolv.conf

Edit the nameserver to have the DNS forwader settings of your choice.

Save and Exit Nano.

Install curl using the command

sudo apt-get –y install curl

Download and install pi-hole:
wget –O basic-install.sh https://install.pi-hole.net
chmod +x basic-install.sh

Press OK

You should donate (I did!).  Press OK

Chose wlan0 and press OK (wlan1 is bluetooth)

Choose IPv4, IPv6 or both and press OK

If the IP address is correct, select YES

If the IP address you have assigned the CHIP is within the DHCP range of your DHCP Server or router, you may need to exclude this IP address, or modify the range.
Click OK

Select the DNS servers to use as forwarders.  If you are not sure, choose Google, and select OK.

Once the install is complete, press OK

You can add additional block lists by doing the following:
sudo cp /etc/pihole/adlists.default /etc/pihole/adlists.list
sudo nano /etc/pihole/adlists.list

Add the bottom to the file (or add your own)

# Additional #
#Peter Lowes Ad Server List
#Ublock Filters
Reboot the chip with
sudo reboot

Change the DNS on your computer / or router to point to the IP address of the chip.  In a Window DNS environment, change the DNS forwarders

You can check the status and modify the blocklist / whitelist by navigating to:


Installing C.H.I.P headless

Requirements:  miniUSB cable; C.H.I.P, computer running linux, wireless network.
Optional – Powered USB hub, additional miniUSB cable, computer running Windows.

I recieved my C.H.I.P, but had no spare keyboard, mouse, or monitor.  To get the device configured I did the following:
Download and install Chrome https://www.google.com/chrome/
In chrome, navigate to http://flash.getchip.com/

I chose Headless 4.4.

If you are on a windows computer, click Install the Driver.  Download and run the installer.


And click Finish.

Click Next

Connect a paperclip, or a 1/2 stripped twist tie to FEL and GND

Connect the C.H.I.P to the computer using a USB cable.

If the flashing fails, disconnect the C.H.I.P.  Close Chrome, and reopen Chrome and navigate to http://flash.getchip.com/ – begin the process again (if you already installed the drivers, you don’t need to install them again)

Once the flash has completed, close Chrome, and remove the paperclip / twist tie jumper.  If necessary – connect the C.H.I.P to the linux computer (used a raspberry pi – it was necessary to use a powered USB hub in order to get the C.H.I.P to have enough power).
Install screen on the linux computer: sudo apt-get install screen

Type the command dmesg | tail

In the output above, you can see the C.H.I.P is presented to the OS as ttyACM1. 
Type the following command: screen /dev/ttyACM1 (replace ttyACM1 with the USB port number from the output of dmesg | tail
If the screen appears blank, press <ENTER>

The default credentials are chip / chip

Type the command sudo nmtui

Authenticate if necessary

Select Activate a Connection

Select your wifi connection from the list and press <ENTER>
Enter your wireless passkey and press <ENTER>

Once connected, you will see an asterisk next to the network you are connected to

Select Quit
type sudo nmtui again

Select Edit a connection

Select your wireless connection and select Edit…

Go to the bottom, and select Automatically connect and Available to all users.

If you wish, open IPv4 Configuration, and manually assign an IP address, Gateway and DNS servers.

Select OK and Quit
Verify you can access the internet.  ping www.google.com
CTRL-C to finish the ping.

Run the command sudo apt-get update to update the package list
Run the command sudo apt-get dist-upgrade
Select ‘Y’ to continue if prompted.
This may take some time.
Once completed, uninstall group-bin and configuration files
sudo apt-get purge cgroup-bin
It may / may not have anything to uninstall.  This can prevent the unit from booting.
Change the name of the device
sudo nano /etc/hostname
CTRL-X, Y and <Enter> to save the name
sudo nano /etc/hosts
Change the line     chip
to     <new name of the device>
CTRL-X, Y and <Enter> to save the name
Reboot the unit with
sudo reboot
you shuld now be able to connect to the chip with SSH via wifi.


Configure Raspberry Pi as a router (ethernet and wifi) on Jessie

I used these instructions to create a router with 2 ethernet and 1 wireless connection.  These instructions can be modified for more wireless or more ethernet connections.  I was setting up eth1 as the WAN connection, eth0 and wlan0 as LAN connections.  Wlan0 was to broadcast DHCP from the PI, eth0 would have static IP, and DHCP on this netowrk would be from an external DHCP server.

Pi model B+ running Raspbian Jessie;
Wireless USB dongle;
USB Ethernet Adapter.
In this example I used a Wi-Pi adapter, and a TP-Link UE300
rfkill: a wireless utility
zd1211-firmware: common firmware that works with many Wi-Fi dongles
hostapd: the hostap wireless access point daemon
hostap-utils: supplemental hostap tools
iw: wireless configuration utility
isc-dhcp-server: ISC implementation of DHCP
bridge-utils:  used for connecting multiple Ethernet devices together

Connect to the Pi via SSH

Install requirements by using the command:

sudo apt-get update -y
sudo apt-get install rfkill zd1211-firmware hostapd hostap-utils iw bridge-utils isc-dhcp-server -y

Jessie may have iw preinstalled — if it does and is updated, running the command above will automatically skip it.

Connect the wifi dongle and USB Ethernet adapter

Use the command lsusb to ensure that the USB wireless dongle is being detected

pi@gw:~ $ lsusb
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Use the command iw list to ensure that the adapter has a supported interface mode of AP
Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * WDS
         * monitor
         * mesh point

Use ifconfig to identify which interface is which:


Based on the IP Addresses, I could identify eth0 as my LAN connection, and eth1 will be my WAN connection.

Create a backup of /etc/network/interfaces, and edit the file:

sudo cp /etc/network/interfaces /etc/network/interfaces.orig
sudo nano /etc/network/interfaces

Modify the file as appropriate. 

source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback

allow-hotplug eth0
auto eth0
iface eth0 inet static

allow-hotplug eth1
auto eth1
iface eth1 inet static

allow-hotplug wlan0
auto wlan0
iface wlan0 inet static

Take a backup of /etc/hostapd/hostapd.conf and edit the file (it it doesn’t exist, create the file).

sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig
sudo nano /etc/hostapd/hostapd.conf

Modify the file as appropriate

wpa_pairwise=CCMP TKIP

Backup and modify /etc/default/hostapd

sudo cp /etc/default/hostapd /etc/default/hostapd.orig
sudo nano /etc/default/hostapd

Edit the DAEMON_CONF=”” line to point to the hostadp.conf file modified earlier.


Configure DHCP
Create a backup of /etc/dhcp/dhcpd.conf and edit it

sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.orig
sudo nano /etc/dhcp/dhcpd.conf

Make the following changes as appropriate

option domain-name “dmz.anonit.net”;
default-lease-time 86400;
option subnet-mask;
max-lease-time 172800;
option broadcast-address;
option routers;

subnet netmask {
option domain-name-servers,;

Backup and edit /etc/default/isc-dhcp-server and setup the interface to broadcast DHCP on

sudo cp /etc/default/isc-dhcp-server /etc/default/isc-dhcp-server.orig
sudo nano /etc/default/isc-dhcp-server

Find and edit the INTERFACES line to the interface to broadcast DHCP on.


(If you wanted to broadcast DHCP on eth0 as well you could add it in here)

Enable routing and Nat

sudo cp /etc/sysctl.conf /etc/sysctl.conf.orig
sudo nano /etc/sysctl.conf

Edit the file to add the line (or uncomment it)


Enable the translation immediately

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Configure IPTables for NAT

sudo iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
sudo iptables -A FORWARD -i eth1 -o wlan0 -m state –state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth1 -o eth0 -m state –state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth1 -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

sudo iptables-save

If this is the first time modifying iptables, install iptables-persistent by running

sudo apt-get install iptables-persistent

If prompted to make the rules persistent, select YES
If you already have iptables-persistent installed, you can save the iptables rules by running the command

sudo iptables-save

make the changes permanent (starts hostapd and dhcp on boot)

sudo update-rc.d hostapd enable 
sudo update-rc.d isc-dhcp-server enable
save the iptables setup and restore on boot
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" 
Edit the /etc/network/interfaces file and add the following to the end.

up iptables-restore < /etc/iptables.ipv4.nat

Reboot the device and test