admin管理员组文章数量:1400815
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.
本文标签: windowsPowerShell script freezingStack Overflow
版权声明:本文标题:windows - PowerShell script freezing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744222361a2595929.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