Link to home
Start Free TrialLog in
Avatar of iVenture_Solutions
iVenture_SolutionsFlag for United States of America

asked on

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:
File1
File2
File3

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.
Avatar of oBdA
oBdA

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

Avatar of iVenture_Solutions

ASKER

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

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.
Hello.

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.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect. That is exactly what I needed. Thank you so much for the help.