Я видел несколько вопросов здесь, но не видел никакого ответа. У меня есть файл класса, который отображает окно хода выполнения скрипта, и он отлично работает в PowerShell версии 5.1.15063.966, но не работает в PWSH версии 6.0.2.
Я не уверен, что это уместно, но так как я использую это в классе, мне пришлось предварительно загрузить PresentationFramework, а затем (точка) источник включить мой файл класса.
Тестирование (V5):
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\Users\fake> [void][System.Reflection.Assembly]::LoadWithPartialName('PresentationFramework');
PS C:\Users\fake> $newRunspace = [RunspaceFactory]::CreateRunspace();
PS C:\Users\fake> $newRunspace.ThreadOptions = "ReuseThread";
PS C:\Users\fake> $newRunspace.ApartmentState = "STA";
PS C:\Users\fake>
Тестирование (V6):
PowerShell v6.0.2
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS C:\Temp\PS\PowerShell-6.0.2-win-x64> [void][System.Reflection.Assembly]::LoadWithPartialName('PresentationFramework');
PS C:\Temp\PS\PowerShell-6.0.2-win-x64> $newRunspace = [RunspaceFactory]::CreateRunspace();
PS C:\Temp\PS\PowerShell-6.0.2-win-x64> $newRunspace.ThreadOptions = "ReuseThread";
PS C:\Temp\PS\PowerShell-6.0.2-win-x64> $newRunspace.ApartmentState = "STA";
The property 'ApartmentState' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $newRunspace.ApartmentState = "STA";
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
PS C:\Temp\PS\PowerShell-6.0.2-win-x64>
Я сделал GM в обеих версиях, и они действительно разные:
V5:
PS C:\Users\Fake> $newRunspace = [RunspaceFactory]::CreateRunspace();
PS C:\Users\Fake> $newRunSpace | gm
TypeName: System.Management.Automation.Runspaces.LocalRunspace
Name MemberType Definition
---- ---------- ----------
AvailabilityChanged Event System.EventHandler`1[System.Management.Automation.Runspaces.RunspaceAvailab...
StateChanged Event System.EventHandler`1[System.Management.Automation.Runspaces.RunspaceStateEv...
ClearBaseTransaction Method void ClearBaseTransaction()
Close Method void Close()
CloseAsync Method void CloseAsync()
Connect Method void Connect()
ConnectAsync Method void ConnectAsync()
CreateDisconnectedPipeline Method System.Management.Automation.Runspaces.Pipeline CreateDisconnectedPipeline()
CreateDisconnectedPowerShell Method powershell CreateDisconnectedPowerShell()
CreateNestedPipeline Method System.Management.Automation.Runspaces.Pipeline CreateNestedPipeline(), Syst...
CreatePipeline Method System.Management.Automation.Runspaces.Pipeline CreatePipeline(), System.Man...
Disconnect Method void Disconnect()
DisconnectAsync Method void DisconnectAsync()
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetApplicationPrivateData Method psprimitivedictionary GetApplicationPrivateData()
GetCapabilities Method System.Management.Automation.Runspaces.RunspaceCapability GetCapabilities()
GetHashCode Method int GetHashCode()
GetType Method type GetType()
Open Method void Open()
OpenAsync Method void OpenAsync()
ResetRunspaceState Method void ResetRunspaceState()
SetBaseTransaction Method void SetBaseTransaction(System.Transactions.CommittableTransaction transacti...
ToString Method string ToString()
ApartmentState Property System.Threading.ApartmentState ApartmentState {get;set;}
ConnectionInfo Property System.Management.Automation.Runspaces.RunspaceConnectionInfo ConnectionInfo...
Debugger Property System.Management.Automation.Debugger Debugger {get;}
DisconnectedOn Property System.Nullable[datetime] DisconnectedOn {get;}
Events Property System.Management.Automation.PSEventManager Events {get;}
ExpiresOn Property System.Nullable[datetime] ExpiresOn {get;}
Id Property int Id {get;}
InitialSessionState Property initialsessionstate InitialSessionState {get;}
InstanceId Property guid InstanceId {get;}
JobManager Property System.Management.Automation.JobManager JobManager {get;}
LanguageMode Property System.Management.Automation.PSLanguageMode LanguageMode {get;set;}
Name Property string Name {get;set;}
OriginalConnectionInfo Property System.Management.Automation.Runspaces.RunspaceConnectionInfo OriginalConnec...
RunspaceAvailability Property System.Management.Automation.Runspaces.RunspaceAvailability RunspaceAvailabi...
RunspaceConfiguration Property System.Management.Automation.Runspaces.RunspaceConfiguration RunspaceConfigu...
RunspaceIsRemote Property bool RunspaceIsRemote {get;}
RunspaceStateInfo Property System.Management.Automation.Runspaces.RunspaceStateInfo RunspaceStateInfo {...
SessionStateProxy Property System.Management.Automation.Runspaces.SessionStateProxy SessionStateProxy {...
ThreadOptions Property System.Management.Automation.Runspaces.PSThreadOptions ThreadOptions {get;set;}
Version Property version Version {get;}
V6:
PS C:\Temp\PS\PowerShell-6.0.2-win-x64> $newRunspace = [RunspaceFactory]::CreateRunspace();
PS C:\Temp\PS\PowerShell-6.0.2-win-x64> $newRunSpace | gm
TypeName: System.Management.Automation.Runspaces.LocalRunspace
Name MemberType Definition
---- ---------- ----------
AvailabilityChanged Event System.EventHandler`1[System.Management.Automation.Runspaces.RunspaceAvailab...
StateChanged Event System.EventHandler`1[System.Management.Automation.Runspaces.RunspaceStateEv...
Close Method void Close()
CloseAsync Method void CloseAsync()
Connect Method void Connect()
ConnectAsync Method void ConnectAsync()
CreateDisconnectedPipeline Method System.Management.Automation.Runspaces.Pipeline CreateDisconnectedPipeline()
CreateDisconnectedPowerShell Method powershell CreateDisconnectedPowerShell()
CreateNestedPipeline Method System.Management.Automation.Runspaces.Pipeline CreateNestedPipeline(), Syst...
CreatePipeline Method System.Management.Automation.Runspaces.Pipeline CreatePipeline(), System.Man...
Disconnect Method void Disconnect()
DisconnectAsync Method void DisconnectAsync()
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetApplicationPrivateData Method psprimitivedictionary GetApplicationPrivateData()
GetCapabilities Method System.Management.Automation.Runspaces.RunspaceCapability GetCapabilities()
GetHashCode Method int GetHashCode()
GetType Method type GetType()
Open Method void Open()
OpenAsync Method void OpenAsync()
ResetRunspaceState Method void ResetRunspaceState()
ToString Method string ToString()
ConnectionInfo Property System.Management.Automation.Runspaces.RunspaceConnectionInfo ConnectionInfo...
Debugger Property System.Management.Automation.Debugger Debugger {get;}
DisconnectedOn Property System.Nullable[datetime] DisconnectedOn {get;}
Events Property System.Management.Automation.PSEventManager Events {get;}
ExpiresOn Property System.Nullable[datetime] ExpiresOn {get;}
Id Property int Id {get;}
InitialSessionState Property initialsessionstate InitialSessionState {get;}
InstanceId Property guid InstanceId {get;}
JobManager Property System.Management.Automation.JobManager JobManager {get;}
LanguageMode Property System.Management.Automation.PSLanguageMode LanguageMode {get;set;}
Name Property string Name {get;set;}
OriginalConnectionInfo Property System.Management.Automation.Runspaces.RunspaceConnectionInfo OriginalConnec...
RunspaceAvailability Property System.Management.Automation.Runspaces.RunspaceAvailability RunspaceAvailabi...
RunspaceIsRemote Property bool RunspaceIsRemote {get;}
RunspaceStateInfo Property System.Management.Automation.Runspaces.RunspaceStateInfo RunspaceStateInfo {...
SessionStateProxy Property System.Management.Automation.Runspaces.SessionStateProxy SessionStateProxy {...
ThreadOptions Property System.Management.Automation.Runspaces.PSThreadOptions ThreadOptions {get;set;}
Version Property version Version {get;}
Мой вопрос: как мне сделать эквивалент в V6?