Monday, May 23, 2016

Disable Hibernate in Windows

Hibernate is a neat feature that is especially useful on laptops. Hibernate is different than sleep/standby in that with sleep/standby, the system shuts down most of the hardware, including the hard drive, but keeps the RAM powered to save the current state. This will (very) slowly drain the battery, but is extremely fast to resume. Hibernate saves the RAM state to hard disk and powers everything off. This is slower to resume than sleep/standby, but won't drain the battery and is still faster to resume than a full shutdown.

By default on Windows systems, hibernate is enabled. This includes servers, which should probably never enter hibernate state. The problem with hibernate, especially on older servers, is that the system reserves hard disk space large enough to store the contents of the RAM in the C:\hiberfil.sys file, which is a protected system file. If you have a small hard drive and a bunch of RAM, this can very quickly eat up a lot of valuable disk space. The only way to get this space back is to disable hibernate, which in most cases for servers, is a best practice anyway.

The easiest way to disable hibernate is to open a command prompt (cmd.exe) as administrator and run this command:
powercfg.exe -H off

Monday, May 16, 2016

Install ifconfig in RHEL or CentOS

Depending on the OS version and which configuration you selected during installation, you might discover that ifconfig is not installed by default in your new RHEL or CentOS build. Unfortunately, searching yum might not tell you the name of the package you need to install. I'll save you some looking, the package you need is called "net-tools."

You can install net-tools with this command:
# yum -y install net-tools

Monday, May 9, 2016

List All Domain Controllers for a Given Domain Using PowerShell

PowerShell is an awesome way to gather a bunch of useful information about the system you're on or the domains you're connected to.

This useful command will list all of the Domain Controllers for the given domain. Make sure to replace <domain> with your domain.
> Get-ADDomainController -Filter * -server <domain> | Select-Object name, domain

Monday, May 2, 2016

Use PowerShell To Delete Files Older Than

So you have a machine with a bunch of old files that are just taking up space and you want to quickly and easily clear them all out? PowerShell to the rescue. This command will delete all files in the current directory that were created more than 30 days ago. You can change the number of days based on your needs.
> Get-ChildItem | Where-Object{$_.CreationTime –lt (Get-Date).AddDays(-30)} | Remove-Item


Want to clear out the current directory AND all subdirectories? Add the -Recurse flag after Get-ChildItem.
> Get-ChildItem -Recurse | Where-Object{$_.CreationTime –lt (Get-Date).AddDays(-30)} | Remove-Item


Want to suppress any "are you sure" prompts? Add the -Recurse flag after Remove-Item.
> Get-ChildItem -Recurse | Where-Object{$_.CreationTime –lt (Get-Date).AddDays(-30)} | Remove-Item -Recurse

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.