PowerShell for File Management (Part 4)

by [Published on 13 Oct. 2016 / Last Updated on 13 Oct. 2016]

This article continues the discussion of using PowerShell for file management by looking at file screening techniques.

If you would like to read the other parts in this article series please go to:

Throughout this article series, I have been discussing ways of managing files, file systems, and file servers using PowerShell. In this article, I want to continue the discussion by talking about file screens.

For those who might not be familiar with file screens, they are a function of the File Server Resource Manager. File screens are used to limit the types of files that can be written to a specific location. If you look at the figure below, you can see that there are three main components used in file screening – file screens, file screen templates, and file groups.

Image

As you may have already guessed, file screens are the actual policies that control the types of files that are allowed to be saved in a location. File screen templates are similar to file screens, except that they are designed to be reusable. For example, the first file screen template listed in the image above is Block Audio and Video Files. This template could be used as a part of a file screen. By doing so, it becomes possible to protect multiple locations without having to define all of the properties from scratch.

The last component is File Groups. File groups are collections of file extensions that are used for a common purpose. For example, DOCX, XLSX, and PPTX are file extensions that are used by Microsoft Office, and are therefore grouped into the Office Files group along with several other file extensions. File groups make it possible to create file screens that are based on function. For example, an administrator could create a file screen that blocks Microsoft Office files, without having to manually include all of the file extensions used by Microsoft Office.

So now that I have given you a quick crash course in file screens, let’s take a look at some of the ways that Windows PowerShell can be used to interact with the file screening mechanism. Please keep in mind that the techniques that I am about to show you are written with the assumption that you have the File Server Resource Manager installed on your server.

So with that said, we can get started by taking a look at the items that already exist on our server. If for example, you want to view any existing file screens, you can do so by using the Get-FsrmFileScreen cmdlet. Since my server does not yet have any file screens, let’s move on and take a look at the file groups. File groups can be listed by using the Get-FsrmFileGroup cmdlet, as shown below.

Image

The list shown in the figure above provides some useful information, but it is incomplete. You will notice that some of the file groups do not list all of the included extensions. Furthermore, if you were to start creating a lot of custom file groups, it may not be practical to display them all on the screen at the same time. So let’s take a more granular look at a group.

For the sake of demonstration, let’s assume that it is the Office Files group that you are really interested in. Rather than listing every existing file group, you could instead list just the Office Files group by typing this command:

Get-FsrmFileGroup ‘Office Files’

As you can see in the figure below however, this command limits the output to showing only the Office Files group, but the list of file extensions is still condensed.

Image

Normally in PowerShell, you can view the specific information that you are interested in by using the Select-Object cmdlet. For example, you might use Select-Object to display the group name and the file extensions. The command for doing so would be:

Get-FsrmFileGroup ‘Office Files’ | Select-Object Name, IncludePattern

Unfortunately, this command shows the requested objects, but does not expand the list of file extensions. Even formatting the output as a list does not resolve the problem, as shown below:

Image

The trick to revealing the full list of file extensions is to combine the Select-Object cmdlet with a somewhat obscure PowerShell parameter called -ExpandProperty. The resulting command would be:

Get-FsrmFileGroup ‘Office Files’ | Select-Object -ExpandProperty IncludePattern

You can see the output below, although I have cropped the output because of the huge number of file extensions that are revealed.

Image

OK, so we now know how to figure out which file extensions are contained within a group, so let’s turn our attention to FSRM templates. As you saw at the beginning of this article, Microsoft has provided us with several templates by default. The cmdlet that is used to list these templates is Get-FsrmFileScreenTemplate.

As was the case with the Get-FsrmFileGroup cmdlet, entering this cmdlet with no additional parameters causes PowerShell to display all of the existing FSRM templates. Similarly, entering the Get-FsrmFileScreenTemplate cmdlet, followed by a template name, reveals the details for the specified template. You can see what this looks like in the figure below:

Image

There are a number of different objects associated with file screen templates. In fact, not all of those objects are shown in the figure above. If you want to see a full list of the objects that are associated with the Block Audio and Video Files template, you can type this command:

Get-FsrmFileScreenTemplate ‘Block Audio and Video Files’ | Select-Object *

In most cases, there are only three objects that you are going to have to worry about. The first one is Active. A template’s Active object must be set to True in order for the template to be used.

The second object that you will need to know about it Name. As you would expect, each template is assigned a unique name, and the name is commonly used when referencing the template through PowerShell. In the previous figure for example, I used a template’s name to tell PowerShell which template I wanted to view.

The third object that you will need to know about is the Include Group object. The Include Group is what links file groups to the file template. For example, the Block Audio and Video Files template references the Audio and Video Files group. If you wanted to view these items without the rest of the clutter, you could do so by using this command:

Get-FsrmFileScreenTemplate ‘Block Audio and Video Files’ | Select-Object Name, Active, IncludeGroup | Format-List

Here is what the command looks like:

Image

One thing that is worth noting is that there isn’t always a one to one relationship between file groups and file templates. A template can contain multiple file groups. For example, the Monitor Executable and System Files template references both the Executable Files group and the System Files group. You can see these groups and the Monitor Executable and System Files template in the figure below:

Image

As you can see, Windows PowerShell makes it relatively easy to interact with FSRM file screening elements such as groups, templates, and screens. Now that I have shown you the basics of viewing information associated with these elements, it is time to begin taking things a step further. In the next article, I will show you how to use PowerShell to create a screen.

If you would like to read the other parts in this article series please go to:

See Also


The Author — Brien M. Posey

Brien M. Posey avatar

Brien Posey is an MCSE and has won the Microsoft MVP award for the last few years. Brien has written well over 4,000 technical articles and written or contributed material to 27 books.

Advertisement

Featured Links