powershell - 如何从 c# 在 powershell 脚本中设置变量
问题描述
我正在 Powershell 中编写一个脚本,我想在其中从 C# 代码设置一个变量。
我在Install.PS1
文件中有 Powershell 脚本。此代码在Install.PS1
文件中
$guid = (Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall).Name |
% { $path = "Registry::$_"; Get-ItemProperty $path } |
Where-Object { $_.DisplayName -like $filter } |
Select-Object -Property PsChildName
我想$filter
从 C# 代码中设置值。
解决方案
这根本行不通。
用于此 Cmdlet 的第一个无名参数是参数“FilterScript”。此参数需要一个Scriptblock
作为参数值。这个地方不允许使用 C# 代码。
您可以在此处找到更多信息Where-Object
:https ://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/where-object?view=powershell-6
推荐阅读
- android - 我想关闭适配器中的覆盖方法。解决方法是好习惯吗?
- android - 视图寻呼机适配器中的回调更改为空对象
- javascript - Amped Studio 2 - 声音引擎
- visual-studio-code - Visual Studio Code snake_case 单词选择,如 IntelliJ Camel Humps
- javascript - Facebook 登录按钮:已连接
- react-admin - 你可以在配置中禁用 React-Admin Undo 功能吗?
- python - 如何为数据框中的每个单独类别绘制一周中的每一天
- c - 运行时不可分割的循环大小对 openMP SIMD 的影响
- php - php函数(将html添加到主题)不起作用
- php - Laravel 工作检查网站(如果在线)