Start PowerShell ISE with the 2.0 runtime

前端 未结 2 2200
暗喜
暗喜 2021-02-20 13:24

When PowerShell 3.0 is installed, I can force PowerShell to start using the version 2.0

-Version
    Starts the specified version of Windows PowerShell.
    Ente         


        
2条回答
  •  执笔经年
    2021-02-20 14:02

    You can run 2.0 runtime command by creating new PSSession.

    Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0 –ShowSecurityDescriptorUI
    
    # Please consult system admin when your run set-item and Enable-WSManCredSSP command
    Set-Item wsman:localhost\client\trustedhosts -value * -Confirm:$false -Force
    Enable-WSManCredSSP -Role Client –DelegateComputer * -Force
    Enable-WSManCredSSP -Role Server -Force
    
    # For test purpose
    # Get-WSManCredSSP
    # get-item wsman:localhost\client\trustedhosts
    
    $cred = Get-Credential
    $session = New-PSSession -ComputerName $env:COMPUTERNAME -authentication credssp -ConfigurationName PS2 -Credential $cred
    Enter-PSSession $session
    
    # 2.0 runtime
    Add-PSSnapin microsoft.sharepoint.powershell
    $web = Get-SPWeb http://SPSite/
    $web.Url
    
    Exit-PSSession
    
    Unregister-PSSessionConfiguration -Name PS2
    
    Disable-WSManCredSSP -Role Client
    Disable-WSManCredSSP -Role Server
    

    If you don't exit PSSession, you can run 2.0 runtime command from Powershell ISE 3.

提交回复
热议问题