My PowerShell 3.0 script works when I run it logged on as an interactive user RDP to the server using the PowerShell command prompt/console.
Next step was to create a Scheduled Task and put this script to work. Everything is great except one function that calls Internet Explorer in order to load a web page (and cause the remote IIS server's .Net application to initialize). I think I can do this using VBS, but apparently something is wrong when using PowerShell! (The old VBS script is being retired, presumably it is working; the new PowerShell script in development for new version of application, new server.)
PowerShell 3.0 is on Windows Server 2008 R2. Symptom is that the IE process just does not run (if the user account defined in the Scheduled Task is a non-administrator) although the PowerShell script ends. The other symptom is IE process hangs (if the user is elevated to local administrator).
Example VBS code that works:
On Error Resume Next
Set objShell = CreateObject("Wscript.shell")
strURL1 = "http://localhost/appserver/service.asmx?op=Execute"
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.Open "GET", strURL1, FALSE
objHTTP.Send
Wscript.Echo(objHTTP.statusText)
Wscript.Echo(objHTTP.ResponseText) Example PowerShell code that is not working (as described above). The "hang" problem appears to be the test for $oIE.busy goes into an infinite loop waiting for the web server to respond.
Function OnBase-LoadPage {
param([string]$URL,[string]$Logging)
Add-Content -Path $Logging -Value("Loading Web Page")
$oIE=New-Object -COM InternetExplorer.application
$oIE.Navigate($URL)
$oIE.Visible=$false
While ($oIE.busy) {
Start-Sleep 1
Add-Content -Path $Logging -Value("Internet Explorer is busy. Waiting for web page to load ... sleeping 1 second, retrying.") -PassThru
}
$oIEtempstring = $oIE.document.url
Add-Content -Path $Logging -Value("$oIEtempstring `n")
$oIEtempstring = $oIE.document.title
Add-Content -Path $Logging -Value("$oIEtempstring `n")
$oIE.Stop()
$oIE.Quit()
Return ( $Process.ExitCode )
}There is an additional symptom if I attempt to run the PowerShell script unattended when the user is not a in the server's local Administrators' group. That is a message in the Windows System log on the server:
Log Name: System
Source: Microsoft-Windows-DistributedCOM
Date: 7/14/2014 3:14:20 PM
Event ID: 10016
Task Category: None
Level: Error
Keywords: Classic
User: MYDOMAIN\sa_OBweb
Computer: ADMGMT01-VM.mydomain.com
Description:
The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID
{0002DF01-0000-0000-C000-000000000046}
and APPID
Unavailable
to the user MYDOMAIN\sa_OBweb SID (S-1-5-21-823518204-789336058-682003330-28599) from address LocalHost (Using LRPC). This security permission can be modified using the Component Services administrative tool.Again, the PowerShell script works fine when I run it interactively.