首页 > 解决方案 > 如何从 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# 代码中设置值。

标签: powershell

解决方案


这根本行不通。

用于此 Cmdlet 的第一个无名参数是参数“FilterScript”。此参数需要一个Scriptblock作为参数值。这个地方不允许使用 C# 代码。

您可以在此处找到更多信息Where-Objecthttps ://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/where-object?view=powershell-6


推荐阅读