Powershell如何更改defaultrunspace set disableformatupdates false

Powershell how to change the defaultrunspace set disableformatupdates false

我需要在我的 powershell 中更改 "DisableFormatUpdates" 会话状态值。我已经弄清楚如何检索初始会话状态:

[System.Management.Automation.Runspaces.Runspace]::DefaultRunspace.InitialSessionState

DisableFormatUpdates : True

returns 值符合预期。

但是我不明白如何将此值设置为 False,以便我可以完成模块的导入。看起来运行空间是由 SMA 设置的,但我需要为我们需要加载的模块重置此值。

任何帮助将不胜感激,因为在我的 powershell 工作流程的上下文中设置它绝对超出了我的元素。

创建会话状态对象,然后将 属性 设置为 $true$false

PS C:\> $sessionstate = [system.management.automation.runspaces.initialsessionstate]::CreateDefault()
PS C:\> $sessionstate.DisableFormatUpdates = $true
PS C:\> $sessionstate.DisableFormatUpdates
True
PS C:\> $sessionstate.DisableFormatUpdates = $false
PS C:\> $sessionstate.DisableFormatUpdates
False