@@ -197,7 +197,7 @@ internal static PnPConnection CreateWithACSAppOnly(Uri url, string realm, string
197
197
{
198
198
realm = GetRealmFromTargetUrl ( url ) ;
199
199
200
- if ( realm == null )
200
+ if ( realm == null )
201
201
{
202
202
throw new Exception ( $ "Could not determine realm for the target site '{ url } '. Please validate that a site exists at this URL.") ;
203
203
}
@@ -355,7 +355,7 @@ internal static PnPConnection CreateWithManagedIdentity(Cmdlet cmdlet, string ur
355
355
var defaultResource = $ "{ resourceUri . Scheme } ://{ resourceUri . Authority } ";
356
356
cmdlet . WriteVerbose ( "Acquiring token for resource " + defaultResource ) ;
357
357
var accessToken = TokenHandler . GetManagedIdentityTokenAsync ( cmdlet , httpClient , defaultResource , userAssignedManagedIdentityObjectId ) . GetAwaiter ( ) . GetResult ( ) ;
358
-
358
+
359
359
using ( var authManager = new PnP . Framework . AuthenticationManager ( new System . Net . NetworkCredential ( "" , accessToken ) . SecurePassword ) )
360
360
{
361
361
PnPClientContext context = null ;
@@ -751,11 +751,40 @@ internal void InitializeTelemetry(ClientContext context, InitializationType init
751
751
var coreAssembly = Assembly . GetExecutingAssembly ( ) ;
752
752
var operatingSystem = Utilities . OperatingSystem . GetOSString ( ) ;
753
753
754
- ApplicationInsights . Initialize ( serverLibraryVersion , serverVersion , initializationType . ToString ( ) , ( ( AssemblyFileVersionAttribute ) coreAssembly . GetCustomAttribute ( typeof ( AssemblyFileVersionAttribute ) ) ) . Version . ToString ( ) , operatingSystem ) ;
754
+ ApplicationInsights . Initialize ( serverLibraryVersion , serverVersion , initializationType . ToString ( ) , ( ( AssemblyFileVersionAttribute ) coreAssembly . GetCustomAttribute ( typeof ( AssemblyFileVersionAttribute ) ) ) . Version . ToString ( ) , operatingSystem , PSVersion ) ;
755
755
ApplicationInsights . TrackEvent ( "Connect-PnPOnline" ) ;
756
756
}
757
757
}
758
758
759
+ private static string PSVersion => ( PSVersionLazy . Value ) ;
760
+
761
+ private static readonly Lazy < string > PSVersionLazy = new Lazy < string > (
762
+ ( ) =>
763
+
764
+ {
765
+ var caller = AppDomain . CurrentDomain . GetAssemblies ( ) . SingleOrDefault ( a => a . GetName ( ) . Name == "System.Management.Automation" ) ;
766
+ //var caller = Assembly.GetCallingAssembly();
767
+ var psVersionType = caller . GetType ( "System.Management.Automation.PSVersionInfo" ) ;
768
+ if ( null != psVersionType )
769
+ {
770
+ PropertyInfo propInfo = psVersionType . GetProperty ( "PSVersion" ) ;
771
+ if ( null == propInfo )
772
+ {
773
+ propInfo = psVersionType . GetProperty ( "PSVersion" , BindingFlags . NonPublic | BindingFlags . Static ) ;
774
+ }
775
+ var getter = propInfo . GetGetMethod ( true ) ;
776
+ var version = getter . Invoke ( null , new object [ ] { } ) ;
777
+
778
+ if ( null != version )
779
+ {
780
+ var versionType = version . GetType ( ) ;
781
+ var versionProperty = versionType . GetProperty ( "Major" ) ;
782
+ return ( ( int ) versionProperty . GetValue ( version ) ) . ToString ( ) ;
783
+ }
784
+ }
785
+ return "" ;
786
+ } ) ;
787
+
759
788
private static string PnPPSVersionTag => ( PnPPSVersionTagLazy . Value ) ;
760
789
761
790
private static readonly Lazy < string > PnPPSVersionTagLazy = new Lazy < string > (
0 commit comments