未加星标

PowerShell for File Management (Part 4)

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

If you would like to be notified when Brien Posey releases the next part of this article series please sign up to the windowsNetworking.com Real time article update newsletter .;

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

PowerShell for File Management (Part 1) PowerShell for File Management (Part 2) PowerShell for File Management (Part 3)

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.


PowerShell for File Management (Part 4)

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.


PowerShell for File Management (Part 4)

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.


PowerShell for File Management (Part 4)

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:


PowerShell for File Management (Part 4)

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.


PowerShell for File Management (Part 4)

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:


PowerShell for File Management (Part 4)

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:


PowerShell for File Management (Part 4)

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: PowerShellWindowsOffice
分页:12
转载请注明
本文标题:PowerShell for File Management (Part 4)
本站链接:http://www.codesec.net/view/482372.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(26)