title: Change SQL Server service accounts using PowerShell, but no SQL Server WMI provider with LoadWithPartialName
body: <p>I have to change the service accounts of hundreds of SQL Servers and agents.</p>
  <p>Microsoft recommends using the SQL Server configuration manager. This way works fine, but it is horrible if you have to do it hundred times.</p>
  <p>On the more recent servers (Windows Server 2016, SQL Server 2016/2017) that PowerShell works fine:</p>
  <pre><code>$computer = $env:computername
  [void][reflection.assembly]::LoadWithPartialName(&quot;Microsoft.SqlServer.Smo&quot;)
  [void][reflection.assembly]::LoadWithPartialName(&quot;Microsoft.SqlServer.SqlWmiManagement&quot;)
  $wmi = New-Object (&quot;Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer&quot;) $computer
  $wmi.Services | Select Name, DisplayName, Type, StartMode, ServiceState, 
  ServiceAccount | ft -auto
  $sqlserver = $wmi.Services | where {$_.Type -eq &quot;SqlServer&quot;}
  $sqlserver.SetServiceAccount($account, $pw)
  </code></pre>
  <p>But nearly every older server (Windows Server 2008-2012R2, SQL Server 2008-2014) gives me a empty WmiConnectionInfo an the exception:</p>
  <pre><code>ConnectionSettings : Microsoft.SqlServer.Management.Smo.Wmi.WmiConnectionInfo
  Services           : 
  ClientProtocols    : 
  ServerInstances    : 
  ServerAliases      : 
  Urn                : ManagedComputer[@Name='SERVER']
  Name               : SERVER
  Properties         : {}
  UserData           : 
  State              : Existing
  The following exception occurred while trying to enumerate the collection: &quot;SQL Server WMI provider is not available on SERVER.&quot;.
  </code></pre>
  <p>On the older server I checked the loaded assembylies. [reflection.assembly]::LoadWithPartialName(&quot;Microsoft.SqlServer.Smo&quot;).FullName gives  [...] <strong>Version=13.0.0.0</strong> [...].
  SQL Server 2014 is version 12, not 13.</p>
  <p>But even if I load the right (?) versions of the dlls, the result stays the same.</p>
  <pre><code>[reflection.assembly]::Load(&quot;Microsoft.SqlServer.Smo, Version=12.0.0.0, Culture=neutral, PublicKeyToken=...&quot;)
  [reflection.assembly]::Load(&quot;Microsoft.SqlServer.SqlWmiManagement, Version=12.0.0.0, Culture=neutral, PublicKeyToken=...&quot;)
  </code></pre>
  <p>Do I have to load more assemblies with the correct version?</p>
  <p>Is there another recommended way to change the SQL Server service accounts via PowerShell?</p>