Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Management.Automation.Internal;
using System.Management.Automation.Remoting;
using System.Management.Automation.Runspaces;
using System.Runtime.InteropServices;

using Dbg = System.Management.Automation.Diagnostics;

Expand Down Expand Up @@ -341,8 +342,22 @@ public string CertificateThumbprint
/// </summary>
protected override void BeginProcessing()
{
base.BeginProcessing();
#if UNIX
if (ComputerName?.Length > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our common pattern is to check whether a parameter presents.

if (MyInvocation.BoundParameters.ContainsKey(nameof(ComputerName)))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason for this. The code uses the ComputerName property value and thus it makes more sense to do the check on the actual property rather than a pwsh-ism here. It's also cleaner and shorter than accessing a dictionary to check if a key exists vs just checking the property value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there are situations where it's better but I think it's fine here.

{
ErrorRecord err = new(
new NotImplementedException(
PSRemotingErrorInvariants.FormatResourceString(
RemotingErrorIdStrings.UnsupportedOSForRemoteEnumeration,
RuntimeInformation.OSDescription)),
"PSSessionComputerNameUnix",
ErrorCategory.NotImplemented,
null);
ThrowTerminatingError(err);
}
#endif

base.BeginProcessing();
ConfigurationName ??= string.Empty;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal enum PSRemotingErrorId : uint
// OS related 1-9
DefaultRemotingExceptionMessage = 0,
OutOfMemory = 1,
UnsupportedOSForRemoteEnumeration = 2,

// Pipeline related range: 10-99
PipelineIdsDoNotMatch = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="OutOfMemory" xml:space="preserve">
<value>Out of process memory.</value>
</data>
<data name="UnsupportedOSForRemoteEnumeration" xml:space="preserve">
<value>Remote PSSession enumeration with -ComputerName is only supported on Windows and not "{0}".</value>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes no sense to point OS version. Please remove:

Suggested change
<value>Remote PSSession enumeration with -ComputerName is only supported on Windows and not "{0}".</value>
<value>Remote PSSession enumeration with -ComputerName is only supported on Windows.</value>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it provides a few extra debug details and doesn't hurt to include. It's also somewhat helpful to identify where the cmdlet was run when it comes to remoting ones as people may be confused if the OS platform is local or remote based. Including the local OS information in the error helps to avoid that ambiguity.

</data>
<data name="PipelineIdsDoNotMatch" xml:space="preserve">
<value>Pipeline ID "{0}" does not match the InstanceId of the pipeline that is currently running, "{1}".</value>
</data>
Expand Down