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.
Хорошо, мне просто нужно было немного побороться, но я понял это. Я изменил свой оператор for-each на следующий:
foreach ($_ in $drivesContainingShares)
{New-FsrmFileScreen -Path $_ -Template $fileTemplateName}
Затем я удалил эти строки.
$newFileScreen = New-FsrmFileScreen -Path $drivesContainingShares -Template $fileTemplateName
$drivesContainingShares | ForEach{$newFileScreen}
И теперь мои файловые экраны созданы!