I'm trying to get my hands on filling in a form with PowerShell. So I am simply trying to do this:
$ieObject = New-Object -ComObject 'InternetExplorer.Application';
$ieObject.Visible = $true;;
$ieObject.Navigate('https://www.randomizer.org/');
$currentDocument = $ieObject.Document;
$inputbox = $currentDocument.getElementByID('randSets');
$inputbox.value = "My Value";
However this gives me the error
You cannot call a method on a null-valued expression. At line:5 char:1 + $inputbox = $currentDocument.getElementByID("randSets");
I don't exactly know why but my ieObject doesn't have all the properties (I only have 9 when I'm supposed to have around 50)and methods it should have. When I use Get-Member
I can't see Document
in there so is it normal or am I doing something really wrong?
PS C:\Users\n> $ieObject | Get-Member
TypeName: System.__ComObject
Name MemberType Definition
---- ---------- ----------
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type re...
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
ToString Method string ToString()
Thank you in advance!
I am using:
- Windows 10 Enterprise (so I'm thinking maybe my company blocked some features, I will check with my IT department)
- Powershell version is 5.1
- Internet explorer version 11.885
EDIT: as suggested in the comment I tried to use VBA to do the same thing as my powershell script and I got the same error on the Document
object Method 'Document' of object 'IWebBrowser2' failed'
. This means I can't access properly my Internet Explorer application. In this case I think I should wait for the final answer of my IT department and then add more to this.
So I have access to the object and every property of it until I use Navigate. Then I get errors even for Get-Member
like:
Get-Member : The following exception occurred while retrieving the string representation for property "Application" : "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"