title: New-CimSession without elevation by providing admin credentials on Windows 10?
body: <p>I need to query some WMI values using PowerShell from Windows 10 devices. The script is executed in the context of a non-admin user by some software distribution tooling.</p>
  <p>There is a local admin account, and for the current purpose (retrieving information before wiping the system) it wouldn't be a problem to put the password in the script. As automation is a hard requirement, there is no way to deal with UAC windows or the user to enter some credentials.</p>
  <p>Is there any way to get</p>
  <pre><code>$sess = New-CimSession -Credential $admincred
  </code></pre>
  <p>to work without running into <code>Access is denied</code>, because it isn't run in an elevated context? Can I somehow self-elevate it by just having the admin credentials?</p>
  <p>[Edit]</p>
  <p>The comments asked to provide more concrete information:</p>
  <p>I want to onboard many unmanaged (i.e. no software distribution tool, no domain join) Windows 10 devices to Windows Autopilot.</p>
  <ul>
  <li><p>The devices are not at a specific site.</p>
  </li>
  <li><p>The device vendor can't provide the information.</p>
  </li>
  <li><p>The users don't have administrative privileges</p>
  </li>
  <li><p>The users don't know the local admin password (I do)</p>
  </li>
  <li><p>Exposing the local admin password is less of a problem than the missing tech knowledge of the users (the password is considered legacy)</p>
  </li>
  <li><p>The firewall is preventing incoming traffic (no RDP, WinRM)</p>
  </li>
  <li><p>Code <a href="https://www.powershellgallery.com/packages/Get-WindowsAutoPilotInfo/3.5/Content/Get-WindowsAutoPilotInfo.ps1" rel="nofollow noreferrer">(Source)</a>:</p>
  <p>$devDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv2/mdm/dmmap -Class MDM_DevDetail_Ext01 -Filter &quot;InstanceID='Ext' AND ParentID='./DevDetail'&quot;)</p>
  </li>
  </ul>
  <p>It is too time consuming to get the information using manual remote sessions with a tool like Teamviewer. Getting the users to download a tool from the intranet and running it would be a way to go. So I created a standalone application that builds and runs a customized PowerShell script. What won't work is getting it to run in an elevated session. I always end up with <code>Access denied</code>.</p>