两种模式之一的Powershell Where对象
我正在编写一个powershell脚本,该脚本将连接到服务器并备份遵循两种模式之一的所有数据库,我当前的代码如下:两种模式之一的Powershell Where对象,powershell,Powershell,我正在编写一个powershell脚本,该脚本将连接到服务器并备份遵循两种模式之一的所有数据库,我当前的代码如下: #The GetDbInstances function is imported from another file GetDbInstances $Server $User $Password | Where-Object { $_.Name -like "*Type1*" -or $._Name -like "*Type2*" } | ForEach-Obje
#The GetDbInstances function is imported from another file
GetDbInstances $Server $User $Password |
Where-Object { $_.Name -like "*Type1*" -or $._Name -like "*Type2*" } |
ForEach-Object {
Backup-SqlDatabase -ServerInstance $Server -Database $_.Name -BackupFile $TargetPath
}
我的问题是在{$\u.Name-like“*Type1*”-或$.\u Name-like“*Type2*”}
部分,它根本不运行,并给我带来错误
$._Name : The term '$._Name' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
我的问题是该表达式的正确语法是什么?检查第二个条件变量
它应该是
$\uName
检查第二个条件变量
应该是
$\uName
您错过了第二个子句中的$\uU。Name而不是$.Name您在第二个子句中漏掉了.$\。名称而不是$.Name