# The first command uses the **Invoke-WebRequest** cmdlet to send a sign-in request. The command specifies a value of "FB" for the value of the *SessionVariable* parameter, and saves the result in the $R variable.When the command completes, the $R variable contains an **HtmlWebResponseObject** and the $FB variable contains a **WebRequestSession** object. $R=Invoke-WebRequest https://website -SessionVariable fb # The second command shows the **WebRequestSession** object in the $FB variable. $FB # The third command gets the first form in the **Forms** property of the HTTP response object in the $R variable, and saves it in the $Form variable. $Form = $R.Forms # The fourth command pipes the properties of the form in the $Form variable into a list by using the Format-List cmdlet. $Form | Format-List # The fifth command displays the keys and values in the hash table (dictionary) object in the Fields property of the form. $Form.fields # The sixth and seventh commands populate the values of the email and pass keys of the hash table in the **Fields** property of the form. You can replace the email and password with values that you want to use. $Form.Fields["username"]="username" $Form.Fields["password"]="password" # The eighth command uses the **Invoke-WebRequest** cmdlet to sign into the Facebook web service.The value of the *Uri* parameter is the value of the **Action** property of the form. The **WebRequestSession** object in the $FB variable (the session variable specified in the first command) is now the value of the *WebSession* parameter. The value of the *Body* parameter is the hash table in the Fields property of the form and the value of the *Method* parameter is POST. The command saves the output in the $R variable. $R=Invoke-WebRequest -Uri ("https://website" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields # When the command finishes, the **StatusDescription** property of the web response object in the $R variable indicates that the user is signed in successfully. $R.StatusDescription
$picPath = "D:\File path\Document.csv" # Then I tried to use the Invoke-WebRequest cmdlet, but got an error: Unauthorized $R=Invoke-WebRequest -Uri ("https://website" + $Form.Action) -Method Put -Infile $picPath # I used the $Form | Format-List and saw the Method was Post, so I changed it to Post and got a different error: The selected resource was not found $R=Invoke-WebRequest -Uri ("https://website" + $Form.Action) -Method Post -Infile $picPath
From novice to tech pro — start learning today.