Monday, April 25, 2016

Determine PowerShell Version

PowerShell Cmdlets and syntax will sometimes vary from version to version. Its nice to have an easy way to check what version of PowerShell is installed on a system.There are a couple of ways to to this:
> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  122


Alternatively, you can also use the Get-Host command:
> (get-host).version

Major  Minor  Build  Revision
-----  -----  -----  --------
5      0      10586  122

Monday, April 18, 2016

Write ISO to USB drive in OS X

OS X systems natively support writing disk images to USB drives, however they often need to be converted to a more Mac friendly format first. Start by converting the image to DMG format. In my case, I'm converting a DBAN ISO, but substitute these values with the file you want to convert.
$ hdiutil convert ~/dban-2.3.0_i586.iso -format UDRW -o ~/dban-2.3.0_i586.dmg
Reading DBAN                             (Apple_ISO : 0)…
.............................................................................
Elapsed Time:  1.172s
Speed: 13.6Mbytes/sec
Savings: 0.0%
created: /Users/myaccount/src/os/dban-2.3.0_i586.dmg


Next, plug in the USB drive and list all the available disks.
$ diskutil list
/dev/disk0
   #:                       TYPE NAME                  SIZE       IDENTIFIER
   0:      GUID_partition_scheme                      *250.1 GB   disk0
   1:                        EFI EFI                   209.7 MB   disk0s1
   2:                  Apple_HFS OS X                  249.7 GB   disk0s2
/dev/disk1
   #:                       TYPE NAME                  SIZE       IDENTIFIER
   0:     Apple_partition_scheme                      *17.4 MB    disk1
   1:        Apple_partition_map                       32.3 KB    disk1s1
   2:                  Apple_HFS Flash Player          17.4 MB    disk1s2
/dev/disk2
   #:                       TYPE NAME                  SIZE       IDENTIFIER
   0:     Apple_partition_scheme                      *18.1 MB    disk2
   1:        Apple_partition_map                       32.3 KB    disk2s1
   2:                  Apple_HFS Flash Player          18.1 MB    disk2s2
/dev/disk3
   #:                       TYPE NAME                  SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                      *8.0 GB     disk3
   1:                 DOS_FAT_32 UNTITLED 1            8.0 GB     disk3s1


In my case, my USB drive is /dev/disk3. Now unmount that drive, but leave it plugged into the system.
$ diskutil unmountDisk /dev/disk3
Unmount of all volumes on disk3 was successful


Write the image to disk using the dd command.
$ sudo dd if=dban-2.3.0_i586.dmg of=/dev/disk3 bs=1m
Password:
15+1 records in
15+1 records out
16719872 bytes transferred in 6.551918 secs (2551905 bytes/sec)


Finally, eject the disk.
$ diskutil eject /dev/disk3
Disk /dev/disk3 ejected

Monday, April 11, 2016

Change the Active Windows Firewall Profile

The Windows Firewall uses three different profiles: 1) Domain, 2) Private, and 3) Public. The system will assign a profile based on the network it is connected to. The Domain profile is only used when the computer is a member of a domain and a domain controller can be reached. The Private profile is intended for trusted networks, such as at home or in a work environment where there is not a domain. The Public profile is for use on untrusted networks, such as in public places. Each profile has a slightly different default set of rules and can be customized individually.

The Windows Firewall with Advanced Security on Local Computer properties window shows the status of each firewall profile and which profile is currently active.



Unfortunately, there is no easy way to use the GUI to change the active profile. To do that, we'll use Powershell. Too see the active firewall profile, run:
> Get-NetConnectionProfile

Name             : Network  2
InterfaceAlias   : Integrated
InterfaceIndex   : 8
NetworkCategory  : Public
IPv4Connectivity : Internet
IPv6Connectivity : NoTraffic


To change the network profile, you'll have to run Powershell as administrator.
> Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private


The Windows Firewall with Advanced Security on Local Computer properties window now shows the Private profile as active.

Monday, April 4, 2016

Redirect Command Line Output to Files in Linux

When using a Linux shell, often you'll find it useful to write the output of a command to a file instead of to the screen. This could be to edit a configuration file or simply to save the output for later use. There are a couple of ways to do this and each has its use.

To redirect output to a file, you can use the carrot (>). Keep in mind, this will overwrite the file if it already exists or create the file if it does not already exist.
$ echo "Hello world!" > ~/output.txt
$ cat ~/output.txt 
Hello world!


If you use the carrot (>) again to write something to the same file, the original contents will be overwritten (I know I said this twice, that was deliberate). If you want to keep the contents of an existing file, you can use the double carrot (>>) to append the output at the end of the file. The double carrot (>>) will also create the file if it does not already exist.
$ echo "Hello again world!" >> ~/output.txt
$ cat ~/output.txt 
Hello world!
Helo again world!


If you want to write the output of a command to both the screen and to a file, use the tee command. By default tee will overwrite an existing file if it exists and create the file if it does not exist.
$ echo "Hello world!" | tee ~/output.txt
Hello world!
$ cat ~/output.txt 
Hello world!


When using tee, if you want to append to the end of an existing file instead of overwriting it, use the -a flag.
$ echo "Hello again world!" | tee -a ~/output.txt
Hello again world!
$ cat ~/output.txt 
Hello world!
Helo again world!