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!
Related
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 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?
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 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
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.