【发布时间】:2021-06-25 16:32:50
【问题描述】:
我熟悉使用 Set-Variable 命令在 PowerShell 中创建只读变量和常量,如下所示:
Set-Variable -Option ReadOnly, AllScope -Name STANDARD_TOKEN_PARAMS -Force -Value @{
Username = 'username'
Password = 'password'
ClientId = 'clientID'
}
或者替代ReadOnly 和Constant 用于不可删除的变量。
我假设使用ReadOnly 选项我将无法修改集合,但事实并非如此。例如,$STANDARD_TOKEN_PARAMS.someNewEntry = 'newEntry' 有效并相应地修改集合。
是否有类似的命令可用于在 PowerShell 中创建真正的“只读”集合?
【问题讨论】:
标签: powershell readonly-collection