Here is the script I modified slightly from the above post
Set-Location C:$scriptArray = Get-ChildItem \\filesharelocation
$runArray = @()
$dbArray = Get-ChildItem -name
foreach ($script in $scriptArray)
foreach ($db in $dbArray)
if ($db -match $script)
$runArray += $script
The contents of $scriptArray are masterDBPerms.sql, msdbDBPerms.sql, database1DBPerms.sql, database2DBPerms.sql, database3DBPerms.sql etc
the contents of $dbArray are master, msdb, database1, database3 etc (note there is no database2
I thought that -match would macth 'master' to 'masterDBPerms.sql' and likewise for all such that I would end up with another Array ($runArray) with all scripts except database2DBPerms.sql as the database2 does nto exist on that server.
Instead I am getting the following error
The '-match' operator failed: parsing "\\filesharelocation\masterDBperms.sql" - Unrecognized escape sequence \L..
At G:\test.ps1:15 char:17
+ if ($db -match <<<< $script)
i am getting this repeatedly for every loop.