# Get-WindowsFeature when running as service

**URL:** <https://forums.powershell.org/t/get-windowsfeature-when-running-as-service/3494>\
**Category:** PowerShell Help\
**Created:** [December 8, 2014, 9:58am UTC](https://forums.powershell.org/t/get-windowsfeature-when-running-as-service/3494 "2014-12-08T09:58:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mccarths](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mccarths/32/819_2.png) [@mccarths](https://forums.powershell.org/u/mccarths)\
**Post date:** [December 8, 2014, 9:58am UTC](https://forums.powershell.org/t/get-windowsfeature-when-running-as-service/3494/1 "2014-12-08T09:58:41Z")

</div>

Running this bit of PowerShell from C#:

```
import-module ServerManager ; Get-WindowsFeature | Where-Object {$_.Installed -eq 'True'} | Select Name,DisplayName,FeatureType
```

It’s running as a service user, runs fine from command line as that user, but when running in the context of a service it fails miserably.

Does the service user need particular permissions or configuration to be able to do this when running as a service?

Error from the ServiceManager.log is this:

```
3440: 2014-12-05 09:10:34.607 [ExceptionHandler] Error (Id=0) An unexpected exception was found:
System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {BA126AD1-2166-11D1-B1D0-00805FC1270E} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
   at Microsoft.Windows.ServerManager.DirectResult.GetLocalNetworkAdapterInfo()
   at Microsoft.Windows.ServerManager.DirectResult.InitializeNetworkAdapterInfo()
   at Microsoft.Windows.ServerManager.DirectResult.PopulateData()
   at Microsoft.Windows.ServerManager.ServerManagerModel.InternalRefreshDirectResult(Object state)
```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [December 8, 2014, 10:02am UTC](https://forums.powershell.org/t/get-windowsfeature-when-running-as-service/3494/2 "2014-12-08T10:02:23Z")

</div>

It’s possible that the underlying COM object is looking for specific elements of a user profile, which a service won’t have (and can’t be made to have). It isn’t a permission thing, it’s a context thing. You might not be able to force a service to do that.

That said, anything PowerShell can do, C# can do. Given that you know the COM class ID (from the error), you might be able to instantiate it and work with it directly from C#.

---

<div class="post-metadata">

**Author:** ![mccarths](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mccarths/32/819_2.png) [@mccarths](https://forums.powershell.org/u/mccarths)\
**Post date:** [December 12, 2014, 4:39am UTC](https://forums.powershell.org/t/get-windowsfeature-when-running-as-service/3494/3 "2014-12-12T04:39:53Z")

</div>

Ended up using gwmi win32\_serverfeature instead. Not as much information, but it will do for 2008 boxes.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/get-windowsfeature-when-running-as-service/3494/4 "2024-05-16T20:46:38Z")

</div>

Closed on May 16, 2024, 8:46pm UTC


