powershell - Powershell Where-Object 用于两种模式之一
问题描述
我正在编写一个powershell脚本,它将连接到服务器并备份遵循两种模式之一的所有数据库,我当前的代码如下:
#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
}
我的问题在于{ $_.Name -like "*Type1*" -or $._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.
我的问题是该表达式的正确语法是什么?
解决方案
检查第二个条件变量。
它应该是$_.Name
推荐阅读
- android - 在jetpack compose中创建视图和视图上创建替代品的片段?
- javascript - XMLHttp Javascript - 如何删除自动刷新
- plotly - 带有一个下拉列表和多个选择器的 Plotly Dash 散点图(全部)
- angular - 电容存储时序问题
- javascript - 如何在循环中执行事件,直到事件为真
- c# - C#:从数组中删除许多元素
- excel-2010 - 使用 excel 和 Visual Basic 每十秒计数一次
- python - Django 身份验证流程如何工作?【特例】
- node.js - find() 方法不适用于猫鼬中的异步函数
- java - JTable排序和渲染