【问题标题】:Powershell how to change the defaultrunspace set disableformatupdates falsePowershell如何更改defaultrunspace设置disableformatupdates false
【发布时间】:2017-08-31 19:48:40
【问题描述】:

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

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

DisableFormatUpdates : 真

按预期返回值。

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

任何帮助都将不胜感激,因为在我的 powershell 工作流程的上下文中设置它时,我肯定不适合我的元素。

【问题讨论】:

    标签: powershell runspace


    【解决方案1】:

    创建 sessionstate 对象,然后将属性设置为$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
    

    【讨论】:

    • 谢谢先生!事实上,我确实在很多烦恼之后才弄清楚这一点。我认为它必须是 C# 中的布尔集才能设置值,但我错了。非常感谢!
    猜你喜欢
    • 2019-07-09
    • 1970-01-01
    • 2012-08-13
    • 2013-05-27
    • 2018-01-08
    • 1970-01-01
    • 2012-07-06
    • 2014-10-16
    • 2011-05-09
    相关资源
    最近更新 更多