When I run this powershell script, the script keeps freezing. It either intermittently hangs on checkMissingFeatures(); this function calls Get-WindowsOptionalFeature
Does anybody know how to fix this issue?
$featuresList = @("IIS-WebServerRole", "IIS-WebServer", "IIS-CommonHttpFeatures", "IIS-ApplicationDevelopment", "IIS-NetFxExtensibility45", "IIS-Security", "IIS-RequestFiltering", "IIS-DefaultDocument", "IIS-ASPNET45", "IIS-ISAPIExtensions", "IIS-ISAPIFilter", "WCF-Services45", "WCF-HTTP-Activation45", "NetFx4Extended-ASPNET45", "NetFx4-AdvSrvs", "NetFx4Extended-ASPNET45", "WCF-HTTP-Activation", "WCF-NonHTTP-Activation", "NetFx3", "WAS-NetFxEnvironment", "IIS-WebServerManagementTools", "IIS-ManagementScriptingTools", "IIS-IIS6ManagementCompatibility", "IIS-ManagementConsole", "IIS-ManagementService", "IIS-WMICompatibility", "IIS-LegacyScripts", "IIS-WebSockets", "IIS-ApplicationInit", "IIS-ASPNET", "IIS-ASP", "IIS-CGI", "IIS-ServerSideIncludes", "IIS-HttpRedirect", "IIS-WebDAV", "IIS-HttpLogging", "IIS-LoggingLibraries", "IIS-RequestMonitor", "IIS-HttpTracing", "IIS-CustomLogging", "IIS-ODBCLogging", "IIS-HealthAndDiagnostics", "IIS-Performance", "IIS-HttpCompressionDynamic", "IIS-HttpCompressionStatic", "IIS-URLAuthorization", "IIS-IPSecurity", "IIS-BasicAuthentication", "IIS-CertProvider", "IIS-WIndowsAuthentication", "IIS-DigestAuthentication", "IIS-ClientCertificateMappingAuthentication", "IIS-IISCertificateMappingAuthentication", "IIS-HostableWebCore", "IIS-NetFxExtensibility")
# true means enabled
function isWinFeatEnabled($feature) {
$str = Get-WindowsOptionalFeature -Online | Where {$_.FeatureName -eq $feature} | Select State
if ($str -match "Disabled") {
return $false
}
return $true
}
# true means is missing...
function checkMissingFeatures($featuresList) {
foreach ($feature in $featuresList) {
$boolResult = isWinFeatEnabled($feature)
if ($boolResult -eq $false) {
return $true
} else {
}
}
return $false
}
function processWinFeats($featuresList, $isMissing) {
if ($isMissing -eq $true) {
$cmd1 = "\Windows\System32\cmd.exe "
$cmd2 = "/C Start /WAIT DISM /LogPath:log.etw /online /NoRestart /Enable-Feature "
foreach ($feature in $featuresList) {
$cmd2 += "/FeatureName:" + $feature + " "
}
$cmd2 += "& exit 99 \b"
Write-Host "Installing Windows Features..."
Start-Process $cmd1 $cmd2
}
}
Write-Host "Checking for Windows Features..."
$isMissing = checkMissingFeatures($featuresList)
Write-Host "isMissing: " $isMissing
processWinFeats $featuresList $isMissing
Is there a reason why my script is freezing?
When I run this powershell script, the script keeps freezing. It either intermittently hangs on checkMissingFeatures(); this function calls Get-WindowsOptionalFeature
Does anybody know how to fix this issue?
$featuresList = @("IIS-WebServerRole", "IIS-WebServer", "IIS-CommonHttpFeatures", "IIS-ApplicationDevelopment", "IIS-NetFxExtensibility45", "IIS-Security", "IIS-RequestFiltering", "IIS-DefaultDocument", "IIS-ASPNET45", "IIS-ISAPIExtensions", "IIS-ISAPIFilter", "WCF-Services45", "WCF-HTTP-Activation45", "NetFx4Extended-ASPNET45", "NetFx4-AdvSrvs", "NetFx4Extended-ASPNET45", "WCF-HTTP-Activation", "WCF-NonHTTP-Activation", "NetFx3", "WAS-NetFxEnvironment", "IIS-WebServerManagementTools", "IIS-ManagementScriptingTools", "IIS-IIS6ManagementCompatibility", "IIS-ManagementConsole", "IIS-ManagementService", "IIS-WMICompatibility", "IIS-LegacyScripts", "IIS-WebSockets", "IIS-ApplicationInit", "IIS-ASPNET", "IIS-ASP", "IIS-CGI", "IIS-ServerSideIncludes", "IIS-HttpRedirect", "IIS-WebDAV", "IIS-HttpLogging", "IIS-LoggingLibraries", "IIS-RequestMonitor", "IIS-HttpTracing", "IIS-CustomLogging", "IIS-ODBCLogging", "IIS-HealthAndDiagnostics", "IIS-Performance", "IIS-HttpCompressionDynamic", "IIS-HttpCompressionStatic", "IIS-URLAuthorization", "IIS-IPSecurity", "IIS-BasicAuthentication", "IIS-CertProvider", "IIS-WIndowsAuthentication", "IIS-DigestAuthentication", "IIS-ClientCertificateMappingAuthentication", "IIS-IISCertificateMappingAuthentication", "IIS-HostableWebCore", "IIS-NetFxExtensibility")
# true means enabled
function isWinFeatEnabled($feature) {
$str = Get-WindowsOptionalFeature -Online | Where {$_.FeatureName -eq $feature} | Select State
if ($str -match "Disabled") {
return $false
}
return $true
}
# true means is missing...
function checkMissingFeatures($featuresList) {
foreach ($feature in $featuresList) {
$boolResult = isWinFeatEnabled($feature)
if ($boolResult -eq $false) {
return $true
} else {
}
}
return $false
}
function processWinFeats($featuresList, $isMissing) {
if ($isMissing -eq $true) {
$cmd1 = "\Windows\System32\cmd.exe "
$cmd2 = "/C Start /WAIT DISM /LogPath:log.etw /online /NoRestart /Enable-Feature "
foreach ($feature in $featuresList) {
$cmd2 += "/FeatureName:" + $feature + " "
}
$cmd2 += "& exit 99 \b"
Write-Host "Installing Windows Features..."
Start-Process $cmd1 $cmd2
}
}
Write-Host "Checking for Windows Features..."
$isMissing = checkMissingFeatures($featuresList)
Write-Host "isMissing: " $isMissing
processWinFeats $featuresList $isMissing
Is there a reason why my script is freezing?
Share Improve this question edited Mar 25 at 1:34 Lex Li 63.4k11 gold badges124 silver badges161 bronze badges asked Mar 25 at 0:46 Erik343Erik343 3335 silver badges15 bronze badges 13 | Show 8 more comments1 Answer
Reset to default 0I found that if you disable quick edit, the powershell script works!
This is my .bat file
reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 0 /f
Start "My Installer" powershell.exe -NoProfile -executionpolicy unrestricted .\INSTALL.ps1
I just edited the registry to disable quick edit:
HKEY_CURRENT_USER\Console\QuickEdit
A 1 value is enabled, and a 0 is disabled.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744222362a4563845.html
Get-WindowsOptionalFeature -Online
and then figure out the states of multiple features, but in this script it wastes all the time running that slow command over and over again. – Lex Li Commented Mar 25 at 1:40write-host "$([datetime]::Now) doing something..."
and see if it shows the output. If it looks like it's hanging, add some more logging around the bit of code that appears to have frozen, and gradually narrow it down to where the bottleneck is. – mclayton Commented Mar 25 at 9:23