Getting a Folder Tree Size with PowerShell

PowerShell is a Windows System Admins swiss army knife and there seems to be no limit to the things you can accomplish with it!

It is particularly easy to get the size of a set of folders (e.g. folders within a folder tree) using PowerShell. This is accomplished by getting the total contents size of each directory recursively to an output

Example:

$colItems = Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
foreach ($i in $colItems)
{
    $subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
    $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"
}

Note: This will not include results for any items whic you don’t have read access to.

Ten Handy PowerShell Commands

PowerShell is the command line included with Windows. It is a very handy tool for doing simple tasks without the GUI. In this guide, I’ll show you 10 tips that will improve your Windows Server experience and make your life easier.

Getting a Process

Rather than using the Task Manager or a similar tool, you can use PowerShell to retrieve information about a specific process and kill it, if needed. This will show the process ID (Id ProcessName):

Get-Process ProcessName

Official documentation

Killing a Process

Once you have the process ID of a process, you can kill it:

Stop-Process -id PID

Official documentation

Getting Contents of a File

You can actually get the content of a file (for example a .txt file) and view it in PowerShell:

Get-Content file.txt

Official documentation

Getting Item Information

You can get information about a certain file with the Get-Item command. The cool thing about this is that you can use it to return multiple kinds of data, for example, you can see the last time somebody accessed a file:

$(Get-Item D:\Users\William\Desktop\file.txt).lastaccesstime

Official documentation Continue reading “Ten Handy PowerShell Commands”

Internet Explorer 11 – Cannot Download Files

Default installations of Microsoft Internet Explorer 11 on Windows Server 2012 and Windows Server 2012 R2 do not permit files (e.g. .exe) to be downloaded from untrusted websites. An error will occur similar to “Your current security settings do not allow this file to be downloaded.”

By design, Internet Explorer on hardened servers does not permit downloads without modifying the default IE security policy. To modify this (temporarily or permenantly) do as follows:

1. Open Internet Explorer
2. Navigate to the ‘Tools’ menu (top left, cog)
3. Click ‘Internet options’
4. Click the ‘Security’ tab
5. Click ‘Internet’ then ‘Custom Level’
6. In the settings zone, find the ‘Downloads’ heading.
7. Under ‘Downloads’ the ‘File Download’ option should be visible to you. Select Disable.
8. Click OK and Exit. Restart Internet Explorer.

You will now be able to download files from untrusted websites. Please note that it is not recommended to leave this setting in place on production servers.

Windows 8 ‘godMode’

Although its name suggests perhaps even grander capabilities, Windows enthusiasts are excited over the discovery of a hidden “godMode” feature that lets users access all of the operating system’s control panels from within a single folder.

To enter “godMode,” one need only create a new folder and then rename the folder to the following:

godMode.{ED7BA470-8E54-465E-825C-99712043E01C}

Users are able to have a single place to do everything from changing the look of the mouse pointer to making a new hard-drive partition.

The trick is also said to works with Windows Vista, Windows 7 and Windows 8.

Loopback Check: Cannot access SharePoint from the SharePoint server

The solution is to modify the registry to disable the Loopback check as per Microsoft knowledge base article KB896861.

The loopback check security feature is designed to help prevent reflection attacks on a computer. Therefore, authentication fails if the FQDN or the custom host header that you use does not match the local computer name. Basically this is by design and you will need apply this “fix” if you want to access SharePoint from the server.

The knowledge base article has two methods in it to address the issue, I personally use Method 2 when related to SharePoint:

  1. Click Start, click Run, type regedit, and then click OK.
  2. In Registry Editor, locate and then click the following registry key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
  3. Right-click Lsa, point to New, and then click DWORD Value.
  4. Type DisableLoopbackCheck, and then press ENTER.
  5. Right-click DisableLoopbackCheck, and then click Modify.
  6. In the Value data box, type 1, and then click OK.
  7. Quit Registry Editor, and then restart your computer.

Warning: Please be careful when editing the registry.