Selenium WebDriver Chrome could not be started in Powershell - powershell

I am trying to start the web automation with using Chrome driver and Selenium. But I am getting an error that, web driver was not loaded. Below is my code entered. If someone could help me to correct this and start to automate would be appreciated.
Import-Module 'C:\AHKM\ChromeAutomation\WebDriver.dll'
$WebDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$WebDriver.Navigate().GoToUrl('www.google.com')
Error is below:
You cannot call a method on a null-valued expression.
At line:3 char:9
+ $WebDriver.Navigate().GoToUrl('www.google.com')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

We resolved this issue by supplying the folder where chromedriver.exe is located, e.g.
$WebDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList "C:\TEMP"

Related

Using MAPI to create a PST file with WinRM

I have the following PowerShell code which creates a PST file
enter code Add-Type -assembly "Microsoft.Office.Interop.Outlook"
$Outlook = New-Object -comobject Outlook.Application
$namespace = $Outlook.GetNameSpace("MAPI")
$namespace.AddStore("C:\tmp\file.pst")
Running this code locally works excellent, but I have to run this code remotely. The script is sitting on the Windows machine and I'm starting it from Linux using WinRM (python) in that setup, it hangs on AddStore(). I assume this is related to user/security context but I can't find the resolution or info if it is possible to run it with some configuration changes.
EDIT: Ok, it is not hanging it just taking a long time before it will fail with the following error:
New-Object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed
due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE)).
At C:\\tmp\\pst.ps1:3 char:12
+ $Outlook = New-Object -comobject Outlook.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.
At C:\\tmp\\pst.ps1:4 char:1
+ $namespace = $Outlook.GetNameSpace("MAPI")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\\tmp\\pst.ps1:6 char:1
+ $namespace.AddStore("C:\\tmp\\file.pst")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
'
CO_E_SERVER_EXEC_FAILURE means Outlook.exe and your code are running in different security contexts, and hence the COM system refuses to marshal calls between the two processes.
Firstly, Outlook cannot be used from anything that runs outside of an interactive user context (such as service or a scheduled task). Secondly, does it work if Outlook is not yet running on the target machine?
That being said, Extended MAPI (C++ or Delphi only) code runs in-proc might be able to do the job. If C++ or Delphi are not an option, you can try Redemption (any language - I am its author) - RDOSession.LogonPstStore is probably what you need - it creates and deletes a temporary profile that loads the specified PST file.

I have a problem with "Create an Azure AD App" Specifically with the powershell Script "Create-AADIdentityApp.ps1"

I have installed Azure stack development kit and i am trying to install the App service.
Then when i have to run the PS1 script Create-AADIdentityApp.ps1 i fill in the following parameters
DirectoryTenantName
AdminArmEndpoint
TenantArmEndpoint
CertificateFilePath
Then i get the following error
New-Object : Exception calling ".ctor" with "3" argument(s): "The system cannot find the file specified.
"
At C:\app-service-certificate-install\Create-AADIdentityApp.ps1:81 char:24
+ ... rtificate = New-Object System.Security.Cryptography.X509Certificates. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
does anyone have any experience?
You provided a invalid CertificateFilePath.
It should be Full path to the identity application certificate file generated earlier.
Please check and correct it.

DownloadString Path error

I'm using the Invoke-Expression cmdlet in PowerShell to load modules.
The following code works as intended.
$url="http://pastebin.com/raw/FuxtpN69"
IEX (New-Object System.Net.Webclient).DownloadString($url)
But when I try using variables to split the domain and the page.
$u="http://pastebin.com"
$rl="/raw/FuxtpN69"
$url="$u$rl"
IEX (New-Object System.Net.Webclient).DownloadString($url)
I get the following path error:
Exception calling "DownloadString" with "1" argument(s): "The given path's format is not supported."
At line:8 char:53
+ IEX (New-Object System.Net.Webclient).DownloadString <<<< ($url)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Can someone help me? Thanks in advance.
I think you are running PowerShell as a different account (for example an administrator).
Maybe that account's proxy settings are different that your normal account's?
See the credentials part first,
$webClient.UseDefaultCredentials = $true
Then, Try setting
$client.Proxy = $null
before downloading and see if it helps.

Powershell, enable windows update error

I'm trying to configure windows update with the Microsoft.Update.AutoUpdate COM object with Powershell v4, on a Windows 2008 r2. I'm however running into a little trouble. When trying to set the NotificationLevel, I'm getting the following error (Note running with elevated permissions).
$WUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
$WUSettings.NotificationLevel=4
$WUSettings.save()
Output:
Exception setting "NotificationLevel": "Exception from HRESULT:
0x80240037" At line:1 char:1
+ $WUSettings.NotificationLevel=4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterSetValueTI
Any help greatly appreciated!

Unable to Use Windows Update COM object in RemotePS sessions

Im trying to change the windows update settings in a remote server using powershell, but when i run the below commands it gives me an error.
PS C:\Windows\system32> Enter-PSSession opalisbinary
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.NotificationLevel=2
Property 'NotificationLevel' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< NotificationLevel=2
+ CategoryInfo : InvalidOperation: (NotificationLevel:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.IncludeRecommendedUpdates=$true
Property 'IncludeRecommendedUpdates' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< IncludeRecommendedUpdates=$true
+ CategoryInfo : InvalidOperation: (IncludeRecommendedUpdates:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.Save()
You cannot call a method on a null-valued expression.
At line:1 char:18
+ $AUSettings.Save <<<< ()
+ CategoryInfo : InvalidOperation: (Save:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Although when i run it locally on the server it works fine...
Could anyone please help me.
Does it work when you connect via Remote desktop and run the commands? It also depends on the bittnes. I don't know the Microsoft.Update.AutoUpdate, so I'm just guessing, but - is it available for x64 version of PowerShell? In other words if you run it locally in x64 version and x86, do you see the errors?
I am sorry, I could not find a real answer. What I found is this link which states that remote PS sessions can be used with SCCM 2012, but they could not with SCCM 2007.
This does not help you, but it seems that not all COM objects are compatible with remote PS sessions.