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
Related
After trying to use ConvertTo-Application and New-WebApplication, I've had no luck converting a folder to an app when it's located on a network share.
I receive a "Path doesn't belong to 'WebAdministration' provider"
I've scoured the internet trying to find a solution, including several links from stackoverflow.
Basically I'm making a GUI script to create a website, convert folders to webapps, I have two comboboxes for selecting current websites and AppPools. The GUI also let's me create AppPools. The GUI works great, but I'm just trying to get this one feature of it going.
This feature of the script is something that is required by management.
New-WebApplication -Name $Name2 -Site $SiteN -PhysicalPath $Path -ApplicationPool $AppP
(also)
ConvertTo-WebApplication -PSPath "\\domain.local\webstuff\WebSites\Dev\Internet\foldername\scriptdevsite\scriptdevsite2\SiteApp1"
Now, I realize that ConvertTo-WebApplication is for converting Virtual Directories to apps, but I wanted to try this and see if it'll work.
The New-Website command works great, but it makes apps and leaves the folders.
So I'll get scriptdevsite2\SiteApp1\SiteApp1, not going to work.
We have websites that have physical folders that sometimes need to be converted to an application and occasionally removed for testing.
Likely going to have to implement some C# for this, I've been checking into Application Class.
But it's not very helpful, at least not to me.
I'm still new to this site, so if there's anything I'm leaving out, I apologize in advance.
Thank you for your help
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.
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.
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.
Is it possible to hook a custom dialog into the new PowerShell ISE (Integrated Scripting Environment) that replaces the existing .NET WinForms dialog. I am talking about the dialog that the Read-Host cmdlet launches to request for user input.
For example, see this URL:
http://www.microsoft.com/technet/scriptcenter/resources/pstips/feb08/pstip0208.mspx
Drop the full code into Notepad.
Add the first line:
function read-host {
Add the last line:
}
Copy all the contents from Notepad.
Paste it all into your PowerShell console.
Now, if you call read-host, you're going to see a new Windows Form.
Now, if I open other windows, it remains on top, but it seems it is not the top-most because I see it over everything else, but still need to click on it to make it active.
What you CAN do is create a custom function that overrides Read-Host, so you're effectively usurping Read-Host and subbing your own functionality.
I don't believe you can, no. You'd need to write your own hosting application. The ISE does have its own object model - I'm asking if what you're after is possible.