I wrote a scrip in Powershell to open ie and get webpage content automatically every minute to check if my API for website is working correctly:
$ie = New-Object -com internetexplorer.application
$ie.navigate($url)
...
$ie.Quit()
After a month my disk C is strangely filled up with IE temporary files, nearly 20GB. I think maybe it's related to my script. The version is Internet Explorer 10.
So how can I open ie without generating these files ? Thanks.
I believe it is better to say not how not to generate cache files at opening but how to clear them after this. As far as I see it now here you can try to clear those files by yourself as here. Or you can set up IE to clear them by itself as per here. Also here some help.
Related
My main goal is to periodically poll a file hosted by a PaaS provider (Azure) to prevent it from becoming cold. It is a 600K+ pdf, so if I poll it once a minute, this could generate a significant amount of data (more than 20GB) per month.
The two methods I tried both perform full download of the data:
Invoke-WebRequest -Uri https://app.whatever.com/docs/staywarm.pdf
((New-Object Net.WebClient).DownloadString('https://app.whatever.com/staywarm.pdf'))
I'd like to only get the first 1K, or even just the first 100 bytes. My theory that even that should keep that file warm.
I have the "Always on" turned on already. So it's interesting that the PDF still often takes 20 seconds to start downloading. The named PDF BTW is a Terms of Service PDF which has to be accepted by the user before login. So when it has to download the application itself should be warm already, since all the files (HTML, CSS, JS) related to the login page had to be served to the browser. So I thought that individual files like that big PDF can remain cold, although the app itself is warm?
You may turn on the Always On option:
It will prevent your app from being idled out due to inactivity
If you still want to use your way, you may just program to make your web app response a empty string to a specific path. For example: in .NET web application, you can directly response one OK action result for path '/check'.
Currently I have this script I execute:
$wc = (New-Object Net.WebClient).OpenRead('https://app.whatever.com/docs/staywarm.pdf')
$tr = New-Object -TypeName System.IO.StreamReader -ArgumentList $wc
$tr.ReadLine()
$tr.Close()
I am new to Powershell and after having a few ideas and deciding to tinker around a bit I noticed that I can write a script in Poswershell that will make a search request on a search engine that I specify.
The issue is I am not sure exactly how it works. How is this script able to know how to open my web browser when all I did was specify a string filled with an address?
I have searched up other posts and have not found anything close to what I am asking (I believe).
Here is my source and I will also add an image.
[String]$SearchFor = "bing rewards"
$Query = "http://www.bing.com/search?q=$SearchFor"
Start $Query
Thank you all for your help.
Read help on start-process
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/start-process
If you specify a non-executable file, Start-Process starts the program
that is associated with the file, similar to the Invoke-Item cmdlet.
So if I would have a TXT File in C:\test.txt and run
start-process c:\test.txt
It would open my default application assiociated with that file. On my PC it would open test.txt in notepad.
Hope that makes it clear now.
It simply uses the default application to open URLs on your desktop i.e. your default Internet browser.
Same behavior if you paste the URL (without variables) in your Start > Run box.
Objective : programmatically upload documents to Sharepoint
Issues :
When trying to use : [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") it does not error but it does error when I try to use the objects it contains. Such as New-Object Microsoft.SharePoint.SPSite($url). The fix to this is to download the "Microsoft.Sharepoint.dll" which is contained in the web extensions folder on the actual server the MOSS is installed on. The problem with that is to be running these scripts on the 2008 server that hosts our Sharepoint site is in no way 'practical' in a big company.
My second approach was to use an internet explorer com object to physically navigate to the page and upload the file from there. After getting the ID of the text box I am not able to set the value, due to what my research shows as "security measures" by Microsoft. when using the get-member cmdlet I am able to see that this html element has a field value that is supposedly 'System.String value {get;set;}'. When I try to set the value nothing happens. The text box itself on the website does not allow you to type anything in. Instead the text box is clickable and brings up a "choose file to upload" window. If I manually choose a file to upload without submitting it, go back to the ISE and and do $uploadText.Value it spits out the file I just chose to console.
My third ditch effort was to use the sendkeys object found in VB to send the path to the web browser and upload the file that way. But when running it the program just hangs and never sends it. This strategy I found at : http://technet.microsoft.com/en-us/library/ff731008 was described to be "a little … temperamental ….". I first make the $ie object open the Microsoft file browser and then try to send keys to it.
The attempted code : (using IE com object, AppActivate and Sendkeys):
$spURL = "https://SharepointSite"
[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate2($spURL)
while($ie.Busy -eq $true) {Start-Sleep 1}
($ie.Document.GetElementByID("zz16_UploadMenu")).click()
while($ie.Busy -eq $true) {Start-Sleep 1}
$uploadText = $ie.Document.GetElementByID("ctl00_PlaceHolderMain_ctl01_ctl02_InputFile")
[Microsoft.VisualBasic.Interaction]::AppActivate("Upload Document")
$uploadText.value = "C:\uploadFile.xlsx" #this line does nothing
$uploadText.click() ## opens up "choose file to upload"
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("C:\uploadFile.xlsx")
And that is it, the browser box pops up, and the script never ends. I have found that some other people have had trouble with setting AppActivate to "choose file to upload" (which I had it set to before I changed it to the IE title "Upload Document"). These problems were all in VB though, I did find what someone claimed to be a fix to "Referencing a Microsoft HTML Library" but it is only going to work for VB, and I need this in powershell. That fix can be found here but it does not work for me.
It seems Microsoft just does not want me to be uploading files programmatically. But before I deemed this "Impossible" I just wanted to post it here first. Any help would be greatly appreciated, I thought everything was possible with powershell! :D
Due to Security reasons you can't do a Fileupload with Comobject IE
I solved that issue by using the watin dll within PS.
I can't Access my Sample from here but you find all you Need at www.watin.org
I wanted to configure a script that would basically take the opening Outlook 2010 for the first time dialog and accept the defaults. We have an exchange server that is currently running that populates the first time fields with the user's AD information. Basically I wanted to write a script in powershell that would accept the default values that AD has filled in and complete the install. Once the install is complete Outlook will set up a copy of the user's mailbox and all of their mail will be pulled down to the computer.
I have been trying and trying in powershell to accomplish the acceptance of defaults to no avail. Is there any possible way to link a powershell script with outlook and have it accept GUI dialogs?
I have not written any code to do this other than a little initialization script in powershell. I am also a powershell newbie so I know enough to create a com object and call that object so that it can open Outlook but that is as far as I can go.
Can someone please give me some help? Here is what I have but it really doesn't work that well:
$mail = new-object -com Outlook.Application
$namespace = $mail.GetNamespace("MAPI")
$folder = $namespace.GetDefaultFolder("olFolderInbox")
$explorer = $folder.GetExplorer()
$explorer.Display()
I'm not sure how far you've gotten with PowerShell, but review this link.
Consider other Windows GUI scripting engines, they should solve this problem pretty easily - more easily than PowerShell scripting.
Try:
AutoHotkey
AutoIt
I ended up using the WASP snap-in at http://wasp.codeplex.com/. It allows UI automation by finding widows and sending commands to those windows. It is easy to use and makes tasks like mine a lot easier. It is only a 32 bit .dll but it works for Powershell >= 2.0. Thank you all for your helpful comments.
I want to display the content of an RTF file in a Powershell RichTextBox.
I am trying to make a kind of custom EULA, and the easiest way to do it would be to write the content in an RTF file and then have it display in a RichTextBox on my form, so the user has to click a checkbox to accept it.
(I'm sure this sits between ServerFault and StackOverflow, but I'm guessing the DotNet gurus on here will know best. ;-) )
Cheers,
Ben
In case anyone else happens upon this wondering where the PowerShell RichTextBox control came from it's a reference to the one in System.Windows.Forms. Here's the code with prerequisite build up:
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$rtb = New-Object System.Windows.Forms.RichTextBox
$rtb.LoadFile($path)
OK - that was easy. Should have got my lazy ass on Google a bit more before posting. Used RichTextFile.Loadfile(c:\myfile.rtf) and it worked a treat.