From 5e6e7ca449eed07cd2221acde5a5d1016b51f27f Mon Sep 17 00:00:00 2001
From: MartinGC94 <42123497+MartinGC94@users.noreply.github.com>
Date: Thu, 24 Mar 2022 23:54:08 +0100
Subject: [PATCH] Add `OutputType` attribute to various commands (#16962)
---
.../commands/management/Computer.cs | 1 +
.../commands/management/TimeZoneCommands.cs | 4 +++-
.../commands/utility/ConvertTo-Html.cs | 1 +
.../commands/utility/TestJsonCommand.cs | 1 +
.../commands/utility/Var.cs | 1 +
.../commands/utility/WebCmdlet/ConvertToJsonCommand.cs | 1 +
.../WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs | 1 +
.../security/CertificateProvider.cs | 1 +
src/Microsoft.WSMan.Management/CredSSP.cs | 2 ++
src/Microsoft.WSMan.Management/InvokeWSManAction.cs | 1 +
src/Microsoft.WSMan.Management/NewWSManSession.cs | 1 +
src/Microsoft.WSMan.Management/PingWSMan.cs | 1 +
src/Microsoft.WSMan.Management/Set-QuickConfig.cs | 1 +
src/Microsoft.WSMan.Management/WSManInstance.cs | 3 +++
.../engine/InitialSessionState.cs | 1 +
.../namespaces/FileSystemProvider.cs | 1 +
.../namespaces/RegistryProvider.cs | 3 +++
17 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs
index 73c2f30950..c12859cb04 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs
@@ -1278,6 +1278,7 @@ $result
///
[Cmdlet(VerbsCommon.Rename, "Computer", SupportsShouldProcess = true,
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2097054", RemotingCapability = RemotingCapability.SupportedByCommand)]
+ [OutputType(typeof(RenameComputerChangeInfo))]
public class RenameComputerCommand : PSCmdlet
{
#region Private Members
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs
index 69e8860f3a..8fdb2c55ac 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/TimeZoneCommands.cs
@@ -17,6 +17,7 @@ namespace Microsoft.PowerShell.Commands
///
[Cmdlet(VerbsCommon.Get, "TimeZone", DefaultParameterSetName = "Name",
HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096904")]
+ [OutputType(typeof(TimeZoneInfo))]
[Alias("gtz")]
public class GetTimeZoneCommand : PSCmdlet
{
@@ -121,6 +122,7 @@ namespace Microsoft.PowerShell.Commands
SupportsShouldProcess = true,
DefaultParameterSetName = "Name",
HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2097056")]
+ [OutputType(typeof(TimeZoneInfo))]
[Alias("stz")]
public class SetTimeZoneCommand : PSCmdlet
{
@@ -159,7 +161,7 @@ namespace Microsoft.PowerShell.Commands
#endregion Parameters
///
- /// Implementation of the ProcessRecord method for Get-TimeZone.
+ /// Implementation of the ProcessRecord method for Set-TimeZone.
///
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Justification = "Since Name is not a parameter of this method, it confuses FXCop. It is the appropriate value for the exception.")]
protected override void ProcessRecord()
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertTo-Html.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertTo-Html.cs
index e72fc825e7..e74e86a9de 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertTo-Html.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertTo-Html.cs
@@ -19,6 +19,7 @@ namespace Microsoft.PowerShell.Commands
///
[Cmdlet(VerbsData.ConvertTo, "Html", DefaultParameterSetName = "Page",
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2096595", RemotingCapability = RemotingCapability.None)]
+ [OutputType(typeof(string))]
public sealed
class ConvertToHtmlCommand : PSCmdlet
{
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs
index cfee0f78aa..488cb4ab4a 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs
@@ -17,6 +17,7 @@ namespace Microsoft.PowerShell.Commands
/// This class implements Test-Json command.
///
[Cmdlet(VerbsDiagnostic.Test, "Json", DefaultParameterSetName = ParameterAttribute.AllParameterSets, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2096609")]
+ [OutputType(typeof(bool))]
public class TestJsonCommand : PSCmdlet
{
private const string SchemaFileParameterSet = "SchemaFile";
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
index e228b309df..f89a5ed537 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
@@ -374,6 +374,7 @@ namespace Microsoft.PowerShell.Commands
///
[Cmdlet(VerbsCommon.New, "Variable", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Low,
HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2097121")]
+ [OutputType(typeof(PSVariable))]
public sealed class NewVariableCommand : VariableCommandBase
{
#region parameters
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
index 2e33a10096..eb8c3e3cc0 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/ConvertToJsonCommand.cs
@@ -16,6 +16,7 @@ namespace Microsoft.PowerShell.Commands
/// This command converts an object to a Json string representation.
///
[Cmdlet(VerbsData.ConvertTo, "Json", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2096925", RemotingCapability = RemotingCapability.None)]
+ [OutputType(typeof(string))]
public class ConvertToJsonCommand : PSCmdlet, IDisposable
{
///
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs
index dafcf3b429..1a46d07404 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeWebRequestCommand.CoreClr.cs
@@ -13,6 +13,7 @@ namespace Microsoft.PowerShell.Commands
/// This command makes an HTTP or HTTPS request to a web server and returns the results.
///
[Cmdlet(VerbsLifecycle.Invoke, "WebRequest", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2097126", DefaultParameterSetName = "StandardMethod")]
+ [OutputType(typeof(BasicHtmlWebResponseObject))]
public class InvokeWebRequestCommand : WebRequestPSCmdlet
{
#region Virtual Method Overrides
diff --git a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
index 1292ecb9b5..7c7627fd52 100644
--- a/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
+++ b/src/Microsoft.PowerShell.Security/security/CertificateProvider.cs
@@ -556,6 +556,7 @@ namespace Microsoft.PowerShell.Commands
[CmdletProvider("Certificate", ProviderCapabilities.ShouldProcess)]
[OutputType(typeof(string), typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.ResolvePath)]
[OutputType(typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.PushLocation)]
+ [OutputType(typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.PopLocation)]
[OutputType(typeof(Microsoft.PowerShell.Commands.X509StoreLocation), typeof(X509Certificate2), ProviderCmdlet = ProviderCmdlet.GetItem)]
[OutputType(typeof(X509Store), typeof(X509Certificate2), ProviderCmdlet = ProviderCmdlet.GetChildItem)]
public sealed class CertificateProvider : NavigationCmdletProvider, ICmdletProviderSupportsHelp
diff --git a/src/Microsoft.WSMan.Management/CredSSP.cs b/src/Microsoft.WSMan.Management/CredSSP.cs
index cd5e6d3fc4..2470a6fc3c 100644
--- a/src/Microsoft.WSMan.Management/CredSSP.cs
+++ b/src/Microsoft.WSMan.Management/CredSSP.cs
@@ -389,6 +389,7 @@ namespace Microsoft.WSMan.Management
/// authentication is achieved via a trusted X509 certificate or Kerberos.
///
[Cmdlet(VerbsLifecycle.Enable, "WSManCredSSP", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096719")]
+ [OutputType(typeof(XmlElement))]
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cred")]
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SSP")]
public class EnableWSManCredSSPCommand : WSManCredSSPCommandBase, IDisposable/*, IDynamicParameters*/
@@ -736,6 +737,7 @@ namespace Microsoft.WSMan.Management
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Cred")]
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SSP")]
[Cmdlet(VerbsCommon.Get, "WSManCredSSP", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096838")]
+ [OutputType(typeof(string))]
public class GetWSManCredSSPCommand : PSCmdlet, IDisposable
{
#region private
diff --git a/src/Microsoft.WSMan.Management/InvokeWSManAction.cs b/src/Microsoft.WSMan.Management/InvokeWSManAction.cs
index 16e91cceae..da92a680ab 100644
--- a/src/Microsoft.WSMan.Management/InvokeWSManAction.cs
+++ b/src/Microsoft.WSMan.Management/InvokeWSManAction.cs
@@ -24,6 +24,7 @@ namespace Microsoft.WSMan.Management
/// -SelectorSet {Name=Spooler}
///
[Cmdlet(VerbsLifecycle.Invoke, "WSManAction", DefaultParameterSetName = "URI", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096843")]
+ [OutputType(typeof(XmlElement))]
public class InvokeWSManActionCommand : AuthenticatingWSManCommand, IDisposable
{
///
diff --git a/src/Microsoft.WSMan.Management/NewWSManSession.cs b/src/Microsoft.WSMan.Management/NewWSManSession.cs
index 25f5bdd598..09b22af992 100644
--- a/src/Microsoft.WSMan.Management/NewWSManSession.cs
+++ b/src/Microsoft.WSMan.Management/NewWSManSession.cs
@@ -26,6 +26,7 @@ namespace Microsoft.WSMan.Management
/// Connect-WSMan.
///
[Cmdlet(VerbsCommon.New, "WSManSessionOption", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096845")]
+ [OutputType(typeof(SessionOption))]
public class NewWSManSessionOptionCommand : PSCmdlet
{
///
diff --git a/src/Microsoft.WSMan.Management/PingWSMan.cs b/src/Microsoft.WSMan.Management/PingWSMan.cs
index b9a0e21f1f..88b443a6ef 100644
--- a/src/Microsoft.WSMan.Management/PingWSMan.cs
+++ b/src/Microsoft.WSMan.Management/PingWSMan.cs
@@ -23,6 +23,7 @@ namespace Microsoft.WSMan.Management
/// service is running.
///
[Cmdlet(VerbsDiagnostic.Test, "WSMan", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2097114")]
+ [OutputType(typeof(XmlElement))]
public class TestWSManCommand : AuthenticatingWSManCommand, IDisposable
{
///
diff --git a/src/Microsoft.WSMan.Management/Set-QuickConfig.cs b/src/Microsoft.WSMan.Management/Set-QuickConfig.cs
index c318ea7647..1ee927558f 100644
--- a/src/Microsoft.WSMan.Management/Set-QuickConfig.cs
+++ b/src/Microsoft.WSMan.Management/Set-QuickConfig.cs
@@ -30,6 +30,7 @@ namespace Microsoft.WSMan.Management
/// 4. Enable firewall exception for WS-Management traffic.
///
[Cmdlet(VerbsCommon.Set, "WSManQuickConfig", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2097112")]
+ [OutputType(typeof(string))]
public class SetWSManQuickConfigCommand : PSCmdlet, IDisposable
{
///
diff --git a/src/Microsoft.WSMan.Management/WSManInstance.cs b/src/Microsoft.WSMan.Management/WSManInstance.cs
index a60ba27010..a29741172e 100644
--- a/src/Microsoft.WSMan.Management/WSManInstance.cs
+++ b/src/Microsoft.WSMan.Management/WSManInstance.cs
@@ -29,6 +29,7 @@ namespace Microsoft.WSMan.Management
/// -SelectorSet {Name=Spooler}
///
[Cmdlet(VerbsCommon.Get, "WSManInstance", DefaultParameterSetName = "GetInstance", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096627")]
+ [OutputType(typeof(XmlElement))]
public class GetWSManInstanceCommand : AuthenticatingWSManCommand, IDisposable
{
#region parameter
@@ -685,6 +686,7 @@ namespace Microsoft.WSMan.Management
/// -SelectorSet {Name=Spooler}
///
[Cmdlet(VerbsCommon.Set, "WSManInstance", DefaultParameterSetName = "ComputerName", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096937")]
+ [OutputType(typeof(XmlElement), typeof(string))]
public class SetWSManInstanceCommand : AuthenticatingWSManCommand, IDisposable
{
#region Parameters
@@ -1324,6 +1326,7 @@ namespace Microsoft.WSMan.Management
/// using specified ValueSet or input File.
///
[Cmdlet(VerbsCommon.New, "WSManInstance", DefaultParameterSetName = "ComputerName", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2096933")]
+ [OutputType(typeof(XmlElement))]
public class NewWSManInstanceCommand : AuthenticatingWSManCommand, IDisposable
{
///
diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs
index c0d4c2cb7c..bfae1b3e6b 100644
--- a/src/System.Management.Automation/engine/InitialSessionState.cs
+++ b/src/System.Management.Automation/engine/InitialSessionState.cs
@@ -3967,6 +3967,7 @@ namespace System.Management.Automation.Runspaces
#>
[CmdletBinding(DefaultParameterSetName = 'ScriptInputSet')]
+[OutputType([System.Management.Automation.CommandCompletion])]
Param(
[Parameter(ParameterSetName = 'ScriptInputSet', Mandatory = $true, Position = 0)]
[string] $inputScript,
diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs
index fd85564370..12c1b193a6 100644
--- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs
+++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs
@@ -37,6 +37,7 @@ namespace Microsoft.PowerShell.Commands
[OutputType(typeof(FileSecurity), ProviderCmdlet = ProviderCmdlet.SetAcl)]
[OutputType(typeof(string), typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.ResolvePath)]
[OutputType(typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.PushLocation)]
+ [OutputType(typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.PopLocation)]
[OutputType(typeof(byte), typeof(string), ProviderCmdlet = ProviderCmdlet.GetContent)]
[OutputType(typeof(FileInfo), ProviderCmdlet = ProviderCmdlet.GetItem)]
[OutputType(typeof(FileInfo), typeof(DirectoryInfo), ProviderCmdlet = ProviderCmdlet.GetChildItem)]
diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs
index 1898c96062..51f768c027 100644
--- a/src/System.Management.Automation/namespaces/RegistryProvider.cs
+++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs
@@ -61,6 +61,9 @@ namespace Microsoft.PowerShell.Commands
[OutputType(typeof(RegistryKey), ProviderCmdlet = ProviderCmdlet.GetItem)]
[OutputType(typeof(RegistryKey), typeof(string), typeof(Int32), typeof(Int64), ProviderCmdlet = ProviderCmdlet.GetItemProperty)]
[OutputType(typeof(RegistryKey), ProviderCmdlet = ProviderCmdlet.NewItem)]
+ [OutputType(typeof(string), typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.ResolvePath)]
+ [OutputType(typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.PushLocation)]
+ [OutputType(typeof(PathInfo), ProviderCmdlet = ProviderCmdlet.PopLocation)]
public sealed partial class RegistryProvider :
NavigationCmdletProvider,
IPropertyCmdletProvider,