I am fairly new to Powershell but thought I would give it a try to attempt to automate some reporting that we have to do. So if you could please explain your answers for what it is doing i would appreciate it.
These are the steps that we doing manual. Go to website and log in using our AD account. Then navigate through a few menus until we get to the page to run the report. The report requires input for range of date and which dept. before it can run.
So my first step is to get the script to log into the website. I first tried to use Get-Credentials which worked great on other scripts that i have used but i can not figure out how to input the username and password into the website fields and for it to then login without me click the login button. The below code is where i started.
#Get Admin Credentials
Function Get-Login {
Clear-Host
Write-Host "Please provide admin credentials (for example DOMAIN\admin.user and your password)"
$Global:Credential = Get-Credential
}
Get-Login
I then found where i could try using invoke-webrequest instead of get-credentials. The problem with that is 1. it appears the username and password has to be hard coded in the script i need it to prompt the user so they use their own credentials and 2. when i did try testing i just kept getting a null array error. Below is the code i was using along with the error...
$R=Invoke-WebRequest -SessionVariable test
$test
$Form = $R.Forms[0]
$Form | Format-List
$Form.fields
$Form.Fields["userid"]="name"
$Form.Fields["password"]="pass"
$R=Invoke-WebRequest -Uri (" + $Form.Action) -WebSession $test -Method POST -Body $Form.Fields
USERID is the name of the input field and Password is the name for the second input field
I am getting this error
Cannot index into a null array.
At C:\logon test.ps1:6 char:1
+ $Form.Fields["userid"]="name"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\logon test.ps1:7 char:1
+ $Form.Fields["password"]="pass"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
I know i can use a simple variable to get the web page to work but the issue with that is it shows the password in plain text and i need it to be hidden/secured since it is the username AD account i do not want anyone else to see it.
Any help would be greatly appreciated
These are the steps that we doing manual. Go to website and log in using our AD account. Then navigate through a few menus until we get to the page to run the report. The report requires input for range of date and which dept. before it can run.
So my first step is to get the script to log into the website. I first tried to use Get-Credentials which worked great on other scripts that i have used but i can not figure out how to input the username and password into the website fields and for it to then login without me click the login button. The below code is where i started.
#Get Admin Credentials
Function Get-Login {
Clear-Host
Write-Host "Please provide admin credentials (for example DOMAIN\admin.user and your password)"
$Global:Credential = Get-Credential
}
Get-Login
I then found where i could try using invoke-webrequest instead of get-credentials. The problem with that is 1. it appears the username and password has to be hard coded in the script i need it to prompt the user so they use their own credentials and 2. when i did try testing i just kept getting a null array error. Below is the code i was using along with the error...
$R=Invoke-WebRequest -SessionVariable test
$test
$Form = $R.Forms[0]
$Form | Format-List
$Form.fields
$Form.Fields["userid"]="name"
$Form.Fields["password"]="pass"
$R=Invoke-WebRequest -Uri (" + $Form.Action) -WebSession $test -Method POST -Body $Form.Fields
USERID is the name of the input field and Password is the name for the second input field
I am getting this error
Cannot index into a null array.
At C:\logon test.ps1:6 char:1
+ $Form.Fields["userid"]="name"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At C:\logon test.ps1:7 char:1
+ $Form.Fields["password"]="pass"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
I know i can use a simple variable to get the web page to work but the issue with that is it shows the password in plain text and i need it to be hidden/secured since it is the username AD account i do not want anyone else to see it.
Any help would be greatly appreciated