diff --git a/src/Commands/Base/ConnectOnline.cs b/src/Commands/Base/ConnectOnline.cs index d6232a184..024646460 100644 --- a/src/Commands/Base/ConnectOnline.cs +++ b/src/Commands/Base/ConnectOnline.cs @@ -572,7 +572,7 @@ private PnPConnection ConnectDeviceLogin() Tenant = TenantExtensions.GetTenantIdByUrl(Url, AzureEnvironment); } - var returnedConnection = PnPConnection.CreateWithDeviceLogin(clientId, Url, Tenant, messageWriter, AzureEnvironment, cancellationTokenSource, PersistLogin, Host); + var returnedConnection = PnPConnection.CreateWithDeviceLogin(clientId, Url, Tenant, messageWriter, AzureEnvironment, cancellationTokenSource, PersistLogin, Host, ErrorActionSetting); connection = returnedConnection; messageWriter.Finished = true; } @@ -790,7 +790,7 @@ private PnPConnection ConnectInteractive() } } LogDebug($"Using ClientID {ClientId}"); - return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, false, PersistLogin, Host); + return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, false, PersistLogin, Host, ErrorActionSetting); } private PnPConnection ConnectEnvironmentVariable(InitializationType initializationType = InitializationType.EnvironmentVariable) @@ -932,7 +932,7 @@ private PnPConnection ConnectWithOSLogin() { WriteObject("Cache used. Clear the cache entry with Disconnect-PnPOnline"); } - return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, true, PersistLogin, Host); + return PnPConnection.CreateWithInteractiveLogin(new Uri(Url.ToLower()), ClientId, TenantAdminUrl, AzureEnvironment, cancellationTokenSource, ForceAuthentication, Tenant, true, PersistLogin, Host, ErrorActionSetting); } private PnPConnection ConnectFederatedIdentity() diff --git a/src/Commands/Base/PnPConnection.cs b/src/Commands/Base/PnPConnection.cs index 62b04cc04..aec183f45 100644 --- a/src/Commands/Base/PnPConnection.cs +++ b/src/Commands/Base/PnPConnection.cs @@ -164,7 +164,8 @@ internal PnPContext PnPContext internal PnP.Framework.AuthenticationManager AuthenticationManager { get; set; } private string _graphEndPoint; - + /// + private static readonly string[] sourceArray = ["stop", "ignore", "silentlycontinue"]; #endregion #region Creators @@ -258,7 +259,7 @@ internal static PnPConnection CreateWithACSAppOnly(Uri url, string realm, string return spoConnection; } - internal static PnPConnection CreateWithDeviceLogin(string clientId, string url, string tenantId, CmdletMessageWriter messageWriter, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool persistLogin, System.Management.Automation.Host.PSHost host) + internal static PnPConnection CreateWithDeviceLogin(string clientId, string url, string tenantId, CmdletMessageWriter messageWriter, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool persistLogin, System.Management.Automation.Host.PSHost host, string ErrorActionSetting = null) { if (persistLogin) { @@ -266,7 +267,10 @@ internal static PnPConnection CreateWithDeviceLogin(string clientId, string url, } if (CacheEnabled(url, clientId)) { - WriteCacheEnabledMessage(host); + if (!sourceArray.Contains(ErrorActionSetting.ToLowerInvariant())) + { + WriteCacheEnabledMessage(host); + } } var connectionUri = new Uri(url); var scopes = new[] { $"{connectionUri.Scheme}://{connectionUri.Authority}//.default" }; // the second double slash is not a typo. @@ -468,7 +472,7 @@ internal static PnPConnection CreateWithManagedIdentity(string url, string tenan } } - internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCredential credentials, bool currentCredentials, string tenantAdminUrl, bool persistLogin, System.Management.Automation.Host.PSHost host, AzureEnvironment azureEnvironment = AzureEnvironment.Production, string clientId = null, string redirectUrl = null, bool onPrem = false, InitializationType initializationType = InitializationType.Credentials) + internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCredential credentials, bool currentCredentials, string tenantAdminUrl, bool persistLogin, System.Management.Automation.Host.PSHost host, AzureEnvironment azureEnvironment = AzureEnvironment.Production, string clientId = null, string redirectUrl = null, bool onPrem = false, InitializationType initializationType = InitializationType.Credentials, string ErrorActionSetting = null) { if (persistLogin) { @@ -476,7 +480,10 @@ internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCr } if (CacheEnabled(url.ToString(), clientId)) { - WriteCacheEnabledMessage(host); + if (!sourceArray.Contains(ErrorActionSetting.ToLowerInvariant())) + { + WriteCacheEnabledMessage(host); + } } var context = new PnPClientContext(url.AbsoluteUri) { @@ -588,7 +595,7 @@ internal static PnPConnection CreateWithCredentials(Cmdlet cmdlet, Uri url, PSCr return spoConnection; } - internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientId, string tenantAdminUrl, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool forceAuthentication, string tenant, bool enableLoginWithWAM, bool persistLogin, System.Management.Automation.Host.PSHost host) + internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientId, string tenantAdminUrl, AzureEnvironment azureEnvironment, CancellationTokenSource cancellationTokenSource, bool forceAuthentication, string tenant, bool enableLoginWithWAM, bool persistLogin, System.Management.Automation.Host.PSHost host, string ErrorActionSetting) { if (persistLogin) { @@ -596,7 +603,10 @@ internal static PnPConnection CreateWithInteractiveLogin(Uri uri, string clientI } if (CacheEnabled(uri.ToString(), clientId)) { - WriteCacheEnabledMessage(host); + if (!sourceArray.Contains(ErrorActionSetting.ToLowerInvariant())) + { + WriteCacheEnabledMessage(host); + } } var htmlMessageSuccess = "PnP PowerShell - Sign InPnP PowerShell
You are signed in now and can close this page.
";