Powershell Creating Filescreen Template via script (result is different from script than if done on commandline) and using array as Filegroup parameter

Trying to manage filescreens on svr2016 and playing with powershell scripting to do this with making most of the parameters variables.  I've got everything working well except with creating a filescreen template.

The cmdlet  New-FSRMFilescreenTemplate has the parameter of -IncludeGroup which you can pass multiple values in the format of a specified array... i.e. @("group1","group2")
or...
"group1"

I'm getting several problems.
1.  If I run it from the command line the groups are correct...

PS C:\> New-FsrmFileScreenTemplate -Name "TEST-TEMPLATE" -IncludeGroup @("Executable Files") -Active

Active                                  : True
Description                        :
IncludeGroup                    :  {Executable Files}
Name                                  :  TEST-TEMPLATE
Notification                        :  
UpdateDerived                  :  False
UpdateDerivedMatching :  False
PSComputername            :

Open in new window


However, if I run that exact same line from inside a script (currently directly from the ISE), the console output shows the exact same, the template is created, but the checked groups when I review the template is always "System Files" regardless of what I specified.

2. Assuming I can get past the weird issue #1, I would like to specify file groups for a given template to be created as an array element within an array...

$arrTempNames = @("template1", "template2")
$arrTempGroups = @(@("filegroup1","filegroup2","filegroup3"),@("filegroup4","filegroup5"))
for ($i=0; $i -lt $arrTempNames.length; $i++) {
      New-FSRMFilescreenTemplate -Name $arrTempNames[$i] -IncludeGroup $arrTempGroups[$i]
}

Open in new window


I cannot get the -IncludeGroup parameter to work with multiple values in any other way other than explicit array declaration as mentioned in the docs, i.e.

   
New-FSRMFilescreenTemplate -Name $arrTempNames[$i] -IncludeGroup @("filegroup1","filegroup2")

Open in new window


I've gone through several other variations of the value passed to -IncludeGroup... nested 2d array as above, straight 1d array, etc.  The only way to get the command to pass is using @("text","text") or @($string_var1, $string_var2) ,   Trying something in a loop like @($arrStrings[1]) or just $arrStrings or @arrStrings  generates an error of "The requested object was not found"... even though doing a Write-Host with the same variable format I specified spits out the proper value.

I've also tried the similar by doing one template at a time by creating the template with just a single group by setting a generic string variable to the current array value in the loop, but then loop through the remaining array elements using to Set-FsrmFileScreenTemplate cmdlet to add each group individually, but keep getting an error.  i.e.

$sCurGroup = $arrTempGroups[$i][$j]
Set-FsrmFileScreenTemplate  -Name $arrTempNames[$i] -IncludeGroup @($sCurGroup)

Open in new window


... even though putting the following right before the cmdlet call

Write-Host $sCurGroup

Open in new window


...spits out the the proper string.
jirikiAsked:
Who is Participating?
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.

GarbsTheTurtleCommented:
Does issue #2 persist in both console and ISE?
0
jirikiAuthor Commented:
I'll have to dig, I've only managed single line cmdlets in console... my DOS past is strong within, however, in the grand scheme, even if it does it is useless to me as I need it to work as a script that I can automate, ingress parameters to, etc.

Had a colleague mentioned they've had issues with dissimilar outcomes between  PS shell and scripts (I assume from the standpoint of cmdlets' results), which I've not heard before and find heavily disturbing.  I've solved this specific issue with DOS batch scripts already and in half the time I've spent getting to this point with PS, but am forcing myself to port and build new various admin actions as so many MS commands are warning of deprication... and I can say I'm not enjoying it.
0
GarbsTheTurtleCommented:
I'm unable to reproduce either issue.

I've tested the command you specified from ISE, from a script in the console, and directly in the console and they all create a TEST-TEMPLATE with Executable Files checked under File Groups. I tested again after adding "Image Files" to the -IncludeGroup array, with expected success. Run on Windows Server 2016, PowerShell version 5.1.

New-FsrmFileScreenTemplate -Name "TEST-TEMPLATE" -IncludeGroup @("Executable Files") -Active
# Deleted TEST-TEMPLATE
New-FsrmFileScreenTemplate -Name "TEST-TEMPLATE" -IncludeGroup @("Executable Files","Image Files") -Active

Open in new window


Issue #2
After I created File Groups matching the names in your example, the script block you provided ran as expected. Two File Screen Templates  were created with the intended File Groups selected. Can you confirm each of the File Groups referenced in $arrTempGroups are already created in the FSRM File Groups section?

$arrTempNames = @("template1", "template2")
$arrTempGroups = @(@("filegroup1","filegroup2","filegroup3"),@("filegroup4","filegroup5"))
for ($i=0; $i -lt $arrTempNames.length; $i++) {
      New-FSRMFilescreenTemplate -Name $arrTempNames[$i] -IncludeGroup $arrTempGroups[$i]
}

Open in new window


Can you post  a sanitized version of your complete script and the error(s) you're seeing at each of your stopping points?

Also, your colleague sounds like a pretty smart guy. You should buy him a beer.
0

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

jirikiAuthor Commented:
Odd, unless I was oblivious to something and I wouldn't put it past myself... hopefully not and I didn't waste my or your time.  I will re-test and do so on a 2nd 2016 system, but might take me a day or two to get time back to this issue.  Thank you for testing and I will try to confirm and if continue to fail, redact the code and screenshots of errors to post.
0
jirikiAuthor Commented:
OK, 1st issue seems to have been an ISE instance/environment issue.  I double checked the code and kept getting the error as before.  Saved it to file and tested on a 2nd server.  As you reported, it worked.  Went back to the original server, same code (literally loaded from copy of same file) and generated an error.  Closed all open ISE's (had 2) plus a console, reopened ISE, loaded same file and executed it worked fine.  So my best guess is either something corrupted or I altered that ISE's instance environment vars somehow to cause the error.   Shame on me for not trying on another system or refreshing the local environment, but I really wish I knew exactly what occurred to cause the problem.

Loaded my working script, did an eye check and found the problem there with the multi-value as I had failed to put quotes around one of the FileGroup names.   Since there were even pairs of "", the ISE didn't point to a problem as different array elements can be of different types.  I was probably a little frustrated at the first issue that I was in a state to miss this simple issue.  So in the Template creation routine, added a code check with the Get-FSRMFIlescreenTemplate  to validate the FileGroups first to ensure my tired/frustrated/whatever eyes can't miss that again.

Awarding points for the effort and 'being a second pair of eyes' on the issue.

So thanks for being a 2nd 'pair of eyes' per say, awarding points for the effort.
0
jirikiAuthor Commented:
One issue seemed to be environmental within the instance of the ISE on a given system.   Second issue was fat-fingering and an abject lesson to validate your input!
0
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.