FSRM Script Using Get-Content to Read Blocked and Allowed files from Text Documents

Hello. We have recently been rolling out File Server Resource Manager and using it to alert us of file names containing the word "*decrypt*". Our script reads the files to screen from a file called screen.txt. The excluded files in this File Group are read from WList.txt.

At this point we have multiple files to exclude in this file group, but when the script gets the content from the file, the file names (all separate lines in the text file) are all entered together on the same line, so instead of excluding:

it excludes File1File1File3.

Here is my code.

$FGroup = Get-Content C:\windows\ltsvc\scripts\Screen.txt
$WList = Get-Content C:\windows\ltsvc\scripts\wList.txt

New-FsrmFileGroup -name "CryptoFileScreen" -includepattern "$FGroup" -ExcludePattern "$WList"

Open in new window

Can anyone help me place this in a proper array?

Thanks for your time.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Remove the double quotes around the arguments. With the double quotes, PS converts the array to a string before it passes it along to the cmdlet.
$FGroup = Get-Content C:\windows\ltsvc\scripts\Screen.txt
$WList = Get-Content C:\windows\ltsvc\scripts\wList.txt

New-FsrmFileGroup -name "CryptoFileScreen" -includepattern $FGroup -ExcludePattern $WList

Open in new window

iVenture_SolutionsAuthor Commented:
Hi oBdA,

I have tried that previously. Taking your advice, I removed the quotes, but I am still ending up with the File Screens' excluded patterns being entered as one single file name.

New-FsrmFileGroup -name "CryptoFileScreen" -includepattern $FGroup -ExcludePattern $WList

Open in new window

Can't reproduce this.
Does it only happen for the exclude file or for the include file as well?
How are you creating the text file?
Did you remove the old "CryptoFileScreen" file group before retrying the script?
What is the output of
(Get-Content C:\windows\ltsvc\scripts\wList.txt).Count

Open in new window

Does this work:
New-FsrmFileGroup -Name "Dummy" -IncludePattern @(".foo", ".bar") -ExcludePattern @("acme", "contoso")

Open in new window

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

iVenture_SolutionsAuthor Commented:
oBdA, I haven't had a chance to try modifying this script, but I will let you know if this works for me. I can tell you that adding  files in the script directly does work when I add multiple files.

Using Get-Content to read from the text files, I am having the same issue with both the pattern I want to include as well as the patterns I want to exclude.
iVenture_SolutionsAuthor Commented:

I was able to get this working properly for 2012 R2. I am not using quotes around the variable names.

In 2008 R2, I am still having the same issue. The line in the script for 2008 R2 is:

filescrn Filegroup Add /Filegroup:"CryptoFileScreen" /Members:$FGroup /nonmembers:$WList

Open in new window

I have tried this with and without the quotes around the variable name. The files in the text document are still showing up as one file name for 2008 R2.
filescrn expects the patterns as "|"-separated list.
The following should work assuming $FGroup and $WList are proper arrays, and that the patterns don't contains spaces:
filescrn Filegroup Add /Filegroup:"CryptoFileScreen" /Members:`"$($FGroup -join '|')`" /nonmembers:`"$($WList -join '|')`"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
iVenture_SolutionsAuthor Commented:
Perfect. That is exactly what I needed. Thank you so much for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.