Unable to invoke web-request for script called in scheduled task for service account - powershell

We have a Powershell script which downloads some zip files from a website and we have called the script in a scheduled task.
The problem is we are not getting the zip files even after the scheduled task is finished successfully. We are using a service account for that. Running the script manually downloads the zip file without any issues. Also, for another user which we use to login into the server, the task is working fine.
The issue started after our service account got locked out because of too many failed attempts in some other system.
I have tried bypassing the execution policy but no luck.
I have tried creating a similar new task but no luck.
I tried Start-in option to provide the task the location of the script but no luck.
After too much troubleshooting, I found the error in the Powershell logs in Event Viewer. Please find the error below:
Error Message = Unable to connect to the remote server
Fully Qualified Error ID = WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
This shows that the task is unable to invoke the web request. Can this be a permission issue? If yes, then how can I provide the required access?
I troubleshooted a bit more and found that the issue is with the proxy. Can somebody tell me how can I resolve this issue? For the local user it is working fine. Even I am able to access the webpage manually through IE. Shall I import proxy settings from IE? If yes then how to do that?

I finally figured out the solution for this. I added proxy details in the script which will force the Invoke web request command to send the request to that proxy server. This thing has resolved my issue.
Regards,
Mitesh Agrawal

Related

The HTTP request to the remote WebDriver server timed out after 60 seconds. Happens only when running through the task scheduler

I'm troubleshooting an Selenium script that runs through the Task Scheduler on a Windows Server. It's running in PowerShell using version 3.0.1 of the Selenium module (found here:https://www.powershellgallery.com/packages/Selenium/3.0.1) with the Edge browser (the one with Chromium).
The "The HTTP request to the remote WebDriver server for URL [localhost] timed out after 60 seconds." error has been quite persistent and only appears when run through the Task Scheduler. The script runs fine when running manually through ISE.
Also to note, there's another script that is more or less the same as the one having the issue, albeit using a slightly different url (same site). This second script runs without issue through the task scheduler. They're performing the same sequence of actions which is why I'm not entirely sure why it would fail for one script but not the other.
I haven't found a suitable solution while looking at other posters facing the same issue. Any help is much appreciated!
I had the same issue. I tried all kinds of code changes but the only step that worked for me was to change the Security Options in Task Scheduler.
Task (right-click) > Properties > General > Switch from Run whether user is logged on or not to Run only when the user is logged on.
I guess this would be a temporary solution. I'll keep looking and update this if I find a better solution.

ansible tower "msg": "ntlm: Bad HTTP response returned from server. Code 403",

I have ansible version 2.9.18. Trying to send the email notification when deployment job completed. When I execute the template, it will call the mail module .yaml file.
But getting below error while executing the mail module:
Below is the mail module configuration for reference:
However I'm able to execute other tasks on the same server like installing the chrome or other agents. I'm wondering whats wrong while calling the mail module.
We were using only host name alone and tried with IP address as well.
Solution:
We have to use server name with full fqdn name (Ex: servername.sampledomain.com)
This helped us to overcome this error.
The other issue was "ansible_shell_type: powershell" was mentioned in the code level. After committing that line helped us to over come power shell related error.

Access Denied Error when issuing Install-AzureWinRMCertificate

I have been working diligently to get Dynamics Installed on Azure, I have made it a good way through the Example-1VM.ps1 before encountering a failure to 'Install-AzureWinRMCertificate' error message indicating access denied.  The error is coming while running the PowerShell script 'New-NAVAdminSession.ps1'  I can see from looking in Azure, much of the work has been done properly from the Example-1VM.ps1 file, but I'm not sure what is next,  Can I manually install the certificate and if so may I know how?  If not, how do I correct this so I can re-run the Example-1VM.ps1 script.
Thanks to Walter slapping me upside the head (kindly of course) to double check if I was running PowerShell ISE as Administrator I was able to get this resolved.
Once I exited PowerShell ISE and re-entered the desktop application with the option 'run as Administrator' all worked fine.
Just goes to show sometimes we are too close to our own problems.
Cheers Walter
According to your error log, it seems a permission issue. Please close your PowerShell and run PowerShell Run as Administrator.

Powershell Grant IIS_IUSRS access to SMTP metabase

Ok I am attempting to transfer a manual change to powershell,
Attempting to grant IIS_IUSRS access to /LM/SmtpSvc/ and /LM/SmtpSvc/1/ nodes in the IIS Metabase.
I have googled extensively and can not find an example of what i am looking for.
I have been trying to play with
$smtp = [wmiclass]‘root\MicrosoftIISv2:IIsSmtpServerSetting'
But I am in a little over my head with WMI.
Any help would be appreciated. This setting is required for resolving
This.
Not an exact answer, but the best I have so far. Following the Guide here I chose option 1 and changed the app pool to network service. I will still work on a way to do the permissions settings with powershell.
Update (solution untested)
I found this answer on another post that details how to do it using scripts in the iis6.0 resource toolkit. To get these scripts on server 2012 you have to install the IIS6.0 resource toolkit, the only way i can find to do a silent install of this one was located here from there you can call the scripts using cscript.exe. I stuck with the changing user on the app pool option because it fits in with other things as well.

How do I get more details on my request error on IIS7

I have deployed a REST service on an external server (IIS7). When I start the service from VS on the Dev server it works fine. But on the server i get:
Request Error, The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service.
How do I get more details on this error? I have looked in the log files directory that is configured under Logging feature for this web site in IIS Manager, but there are no files at all for this site it seems.
You should look in the Windows Event Log using the Event Viewer application (eventvwr.exe). Output to the IIS log files may be buffered so their contents may be updated after a restart, or when IIS is set to do it. Restarting IIS is a surefire way to force this.
Here is a blog post on how to do this.
I'm aware of 3 ways to get nicer errors:
Set UseVerboseErrors in InitializeService method. However, this won't give you anything if your error occurs before InitializeService is called (which happens).
Set IncludeExceptionDetailInFaults to true using an attribute before your service class.
Set IncludeExceptionDetailInFaults to true using web.config.