0

I have a script that scans a server for drives that contains shares. After that I need it to create a file screen from a template that is already created with the same script, that part works fine.

Here is how I am getting a list of drives that have shares:

`$drivesContainingShares =  @(Get-WmiObject Win32_Share | 
                    Select Name,Path,Type | 
                    Where-Object { $_.Type -match '0|2147483648' } | 
                    Select -ExpandProperty Path | 
                    Select -Unique)`

This is the output for $drivesContainingShares

PS C:\> $drivesContainingShares
C:\Windows
C:\

I am having trouble running my command to create a file screen for each drive that contains a share. I have to run this on a lot of servers, any ideas?

Here is where i am at now: I can create a file screen if i manually enter the path in this first line. But I need to automate that, each serer will have different shares.

$newFileScreen = New-FsrmFileScreen  -Path $drivesContainingShares  -Template $fileTemplateName

$drivesContainingShares | ForEach{$newFileScreen} 

I have been trying this many different ways.I get errors like "cannot validate argument on parameter 'Path'. The argument is null or empty.

0

Alright I just had to prevail a little longer but I figured it out. I changed my for-each statement to the following:

 foreach ($_ in $drivesContainingShares) 
{New-FsrmFileScreen  -Path $_  -Template $fileTemplateName}

Then I Deleted these lines.

$newFileScreen = New-FsrmFileScreen  -Path $drivesContainingShares  -Template $fileTemplateName

$drivesContainingShares | ForEach{$newFileScreen} 

And now my filescreens are created!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.