/// <summary> /// Checks if the specified version of PowerShell is installed. /// </summary> /// <param name="version"></param> internal static void CheckIfPowerShellVersionIsInstalled(Version version) { // Check if PowerShell 2.0 is installed if (version != null && version.Major == 2) { #if CORECLR // PowerShell 2.0 is not available for CoreCLR throw new ArgumentException( PSRemotingErrorInvariants.FormatResourceString( RemotingErrorIdStrings.PowerShellNotInstalled, version, "PSVersion")); #else // Because of app-compat issues, in Win8, we will have PS 2.0 installed by default but not .NET 2.0 // In such a case, it is not enough if we check just PowerShell registry keys. We also need to check if .NET 2.0 is installed. try { RegistryKey engineKey = PSSnapInReader.GetPSEngineKey(PSVersionInfo.RegistryVersion1Key); // Also check for .NET 2.0 installation if (!PsUtils.FrameworkRegistryInstallation.IsFrameworkInstalled(2, 0, 0)) { throw new ArgumentException( PSRemotingErrorInvariants.FormatResourceString( RemotingErrorIdStrings.NetFrameWorkV2NotInstalled)); } } catch (PSArgumentException) { throw new ArgumentException( PSRemotingErrorInvariants.FormatResourceString( RemotingErrorIdStrings.PowerShellNotInstalled, version, "PSVersion")); } #endif } }
internal static void CheckIfPowerShellVersionIsInstalled(Version version) { if ((version != null) && (version.Major == 2)) { try { PSSnapInReader.GetPSEngineKey(PSVersionInfo.RegistryVersion1Key); if (!PsUtils.FrameworkRegistryInstallation.IsFrameworkInstalled(2, 0, 0)) { throw new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.NetFrameWorkV2NotInstalled, new object[0])); } } catch (PSArgumentException) { throw new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.PowerShellNotInstalled, new object[] { version, "PSVersion" })); } } }