How can I create a file screen for each path in this variable?

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
задан 30 June 2017 в 16:34
1 ответ

Хорошо, мне просто нужно было немного побороться, но я понял это. Я изменил свой оператор for-each на следующий:

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

Затем я удалил эти строки.

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

$drivesContainingShares | ForEach{$newFileScreen} 

И теперь мои файловые экраны созданы!

0
ответ дан 5 December 2019 в 07:51

Теги

Похожие вопросы