如何在PowerShell模块中使用常量?

时间:2018-06-12 11:06:15

标签: powershell variables module

我想在模块中声明一些变量作为全局常量(Web服务响应代码)。问题是,当我导入模块时(不止一次,有或没有-Force)我得到了

Import-Module : Cannot remove variable ADDED_INCLUSION_STATUS because it is
constant or read-only. If the variable is read-only, try the operation
again specifying the Force option.

我可以使用哪种解决方法/方法?

我的声明如下:

Set-Variable -name STATUS_ABORTED -value 0 -Scope Global -option Constant

1 个答案:

答案 0 :(得分:0)

我认为您应该将声明更改为:

Fresco.initialize(this)

可以使用Set-Variable -name STATUS_ABORTED -value 0 -Scope Global -Option ReadOnly -Force -ErrorAction SilentlyContinue 开关重新定义ReadOnly变量。会话期间有一个常数。如果不关闭PowerShell,则无法更改或删除这些内容。

相关问题