diff --git a/src/ALC/ApplicationInsights.cs b/src/ALC/ApplicationInsights.cs
index 32d71df43..7f05781c7 100644
--- a/src/ALC/ApplicationInsights.cs
+++ b/src/ALC/ApplicationInsights.cs
@@ -26,7 +26,7 @@ public class ApplicationInsights
/// Information on what method has been used to establish a connection
/// The PnP PowerShell version in use
/// The operating system on which PnP PowerShell is being used
- public void Initialize(string serverLibraryVersion, string serverVersion, string initializationType, string assemblyVersion, string operatingSystem)
+ public void Initialize(string serverLibraryVersion, string serverVersion, string initializationType, string assemblyVersion, string operatingSystem, string psVersion = "")
{
// Retrieve an instance of the telemetry client to use
_telemetryClient = TelemetryClientFactory.GetTelemetryClient();
@@ -41,7 +41,8 @@ public void Initialize(string serverLibraryVersion, string serverVersion, string
{ "ConnectionMethod", initializationType.ToString() }, // Information on what method has been used to establish a connection
{ "Version", assemblyVersion }, // The PnP PowerShell version in use
{ "Platform", "SPO" }, // Platform to which the connection has been made
- { "OperatingSystem", operatingSystem} // The operating system on which PnP PowerShell is being used
+ { "OperatingSystem", operatingSystem}, // The operating system on which PnP PowerShell is being used
+ { "PSVersion", psVersion}
};
}
}
diff --git a/src/Commands/Base/PnPConnection.cs b/src/Commands/Base/PnPConnection.cs
index 4e3082b6d..08a29eb3b 100644
--- a/src/Commands/Base/PnPConnection.cs
+++ b/src/Commands/Base/PnPConnection.cs
@@ -197,7 +197,7 @@ internal static PnPConnection CreateWithACSAppOnly(Uri url, string realm, string
{
realm = GetRealmFromTargetUrl(url);
- if(realm == null)
+ if (realm == null)
{
throw new Exception($"Could not determine realm for the target site '{url}'. Please validate that a site exists at this URL.");
}
@@ -355,7 +355,7 @@ internal static PnPConnection CreateWithManagedIdentity(Cmdlet cmdlet, string ur
var defaultResource = $"{resourceUri.Scheme}://{resourceUri.Authority}";
cmdlet.WriteVerbose("Acquiring token for resource " + defaultResource);
var accessToken = TokenHandler.GetManagedIdentityTokenAsync(cmdlet, httpClient, defaultResource, userAssignedManagedIdentityObjectId).GetAwaiter().GetResult();
-
+
using (var authManager = new PnP.Framework.AuthenticationManager(new System.Net.NetworkCredential("", accessToken).SecurePassword))
{
PnPClientContext context = null;
@@ -751,11 +751,40 @@ internal void InitializeTelemetry(ClientContext context, InitializationType init
var coreAssembly = Assembly.GetExecutingAssembly();
var operatingSystem = Utilities.OperatingSystem.GetOSString();
- ApplicationInsights.Initialize(serverLibraryVersion, serverVersion, initializationType.ToString(), ((AssemblyFileVersionAttribute)coreAssembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version.ToString(), operatingSystem);
+ ApplicationInsights.Initialize(serverLibraryVersion, serverVersion, initializationType.ToString(), ((AssemblyFileVersionAttribute)coreAssembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version.ToString(), operatingSystem, PSVersion);
ApplicationInsights.TrackEvent("Connect-PnPOnline");
}
}
+ private static string PSVersion => (PSVersionLazy.Value);
+
+ private static readonly Lazy PSVersionLazy = new Lazy(
+ () =>
+
+ {
+ var caller = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == "System.Management.Automation");
+ //var caller = Assembly.GetCallingAssembly();
+ var psVersionType = caller.GetType("System.Management.Automation.PSVersionInfo");
+ if (null != psVersionType)
+ {
+ PropertyInfo propInfo = psVersionType.GetProperty("PSVersion");
+ if (null == propInfo)
+ {
+ propInfo = psVersionType.GetProperty("PSVersion", BindingFlags.NonPublic | BindingFlags.Static);
+ }
+ var getter = propInfo.GetGetMethod(true);
+ var version = getter.Invoke(null, new object[] { });
+
+ if (null != version)
+ {
+ var versionType = version.GetType();
+ var versionProperty = versionType.GetProperty("Major");
+ return ((int)versionProperty.GetValue(version)).ToString();
+ }
+ }
+ return "";
+ });
+
private static string PnPPSVersionTag => (PnPPSVersionTagLazy.Value);
private static readonly Lazy PnPPSVersionTagLazy = new Lazy(
diff --git a/src/Commands/Base/PnPPowerShellModuleInitializer.cs b/src/Commands/Base/PnPPowerShellModuleInitializer.cs
index 4e2593d65..01fca3a54 100644
--- a/src/Commands/Base/PnPPowerShellModuleInitializer.cs
+++ b/src/Commands/Base/PnPPowerShellModuleInitializer.cs
@@ -10,7 +10,7 @@ namespace PnP.PowerShell.Commands.Base
{
public class PnPPowerShellModuleInitializer : IModuleAssemblyInitializer
{
- private static string s_binBasePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),".."));
+ private static string s_binBasePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ".."));
private static string s_binCommonPath = Path.Combine(s_binBasePath, "Common");