Asked by:
While Trying to send Powershell Data to php form getting the Error: You cannot call a method on a null-valued expression

Question
-
Hi,
I am trying to send the data of powershell to the registration form in php it is showing an error
Code:
Add-Type -AssemblyName Microsoft.VisualBasic
$orderID= hostname
$orderID1= (get-wmiobject -Class win32_bios).SerialNumber
$OrderIDTextBox="hname" # id of the Field Hostname in Registration form$OrderIDTextBox1="sno"# id of the field Serial no in Registration form
$iterator = 1;
$IE = New-Object -ComObject InternetExplorer.Application
$ie.visible = $true
$ie.navigate("http://localhost/asset.php")
While ($IE.Busy -eq $true) {Start-Sleep -Milliseconds 2000}
Start-Sleep -Seconds 3
$ie.Document.getElementById("$orderIDTextBox").value= "$OrderID"
$ie.Document.getElementById("$orderIDTextBox1").value= "$OrderID1"error:
You cannot call a method on a null-valued expression.
At C:\Users\tpladmin\desktop\as.ps1:16 char:1
+ $ie.Document.getElementById("$orderIDTextBox").value= "$OrderID"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\tpladmin\desktop\as.ps1:17 char:1
+ $ie.Document.getElementById("$orderIDTextBox1").value= "$OrderID1"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Created the Value for the $ie with a Com Object. Web page with the url : http://localhost/asset.php is opening but unable to send the data to forms. Please help.
Thanks in Advance.
All replies
-
-
Start by writing your code correctly. It will tell you the exact issue.
$orderID= $env:COMPUTERNAME $orderID1 = (get-wmiobject -Class win32_bios).SerialNumber $ie = New-Object -ComObject InternetExplorer.Application $ie.visible = $true $ie.navigate('http://localhost/asset.php') While($ie.Busy){ Start-Sleep 1 } Try{ if($tb1 = $ie.Document.getElementById('hname')){ $tb1.value= $OrderID if($tb2 = $ie.Document.getElementById('sno')){ $tb2.value= $OrderID1 }else{ Write-Host 'Control "sno" not found' } }else{ Write-Host 'Control "hname" not found' } } Catch{ Throw $_ }
\_(ツ)_/
- Edited by jrvModerator Saturday, November 16, 2019 8:51 PM
- Proposed as answer by LeeSeenLiMicrosoft contingent staff, Moderator Friday, December 6, 2019 7:32 AM
-
Verify that your $ie.Document.getElementById("$orderIDTextBox") has actually returned an Element object. If it hasn't, then you can't get it's value. If there's no Element returned, are you sure you're using "hname" and "son" correctly? Perhaps they're names and not ID's? If they're names, use "getElementByName".
--- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)
- Edited by Rich Matheisen [Ex-MVP (retired)] Saturday, November 16, 2019 9:05 PM
- Proposed as answer by LeeSeenLiMicrosoft contingent staff, Moderator Friday, December 6, 2019 7:32 AM
-
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
LeePlease remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.