I am creating a script using PowerShell to make a http request to an endpoint. I know starting from PowerShell version 3, I can use Invoke-RestMethod or Invoke-WebRequest, but the script is required to be compatible with PowerShell version 2.
As I have googled and read many forums, the most common solution is to use the .Net class System.Net.WebRequest. I am executing the below lines:
$Uri = "https://url"
$Web = [System.Net.WebRequest]::Create($Uri)
And I am facing below error:
Create : Exception calling "Create" with "1" argument(s): "Configuration system failed to initialize"
At line:1 char:32
+ [System.Net.WebRequest]::Create <<<< ($Uri)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Can you please help what might caused this problem?
Related
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"
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.
I am trying to validate the local user credential using the below code:
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$ComputerName)
$status=$DS.ValidateCredentials($UserName, $Password)
I am getting the below error:
Exception calling "ValidateCredentials" with "2" argument(s): "The specified network name is no longer available.
"
At line:1 char:1
+ $ds.ValidateCredentials('User','Password')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : PrincipalOperationException
Please help me to fix this out.
Thanks in advance
Note: I am not getting this error in all the machine. Out of 87 machines i am getting this error in 12 machines alone.
Starting 'server' service fixed the issue
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!
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.