Forum Discussion

Artemis23's avatar
Artemis23
Copper Contributor
Jul 27, 2024

Windows 11 Powershell Null Get-CimInstance

Hi! So I'm trying to create a Kiosk for a downloaded remote desktop application, but every time I run the script, I get the following errors:

 

The property 'Configuration' cannot be found on this object. Verify that the property exists and can be set.

At line:28 char:1

+ $obj.Configuration = [System.Net.WebUtility]::HtmlEncode($assignedAcc ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (:) [], RuntimeException

+ FullyQualifiedErrorId : PropertyNotFound

 

Set-CimInstance : Cannot bind argument to parameter 'InputObject' because it is null.

At line:29 char:30

+ Set-CimInstance -CimInstance $obj

+ ~~~~

+ CategoryInfo : InvalidData: (:) [Set-CimInstance], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Management.Infrastructure.CimCm

dlets.SetCimInstanceCommand

 

This is the full script:

 

 

$user = "RemoteDesktopUser"

$userDesc = "Remote Desktop"

New-LocalUser -Name $user -NoPassword -AccountNeverExpires -UserMayNotChangePassword -Description $userDesc | Set-LocalUser -PasswordNeverExpires $true

Add-LocalGroupMember -SID S-1-5-32-545 -Member $user

$Sid = (Get-LocalUser -Name $user).SID.Value

 

$assignedAccessConfiguration = @"

<?xml version="1.0" encoding="utf-8"?>

<AssignedAccessConfiguration xmlns="http://schemas.microsoft.com/AssignedAccess/2017/config" xmlns:rs5="http://schemas.microsoft.com/AssignedAccess/201810/config" xmlns:v4="http://schemas.microsoft.com/AssignedAccess/2021/config" xmlns:v5="http://schemas.microsoft.com/AssignedAccess/2022/config">

  <Profiles>

    <Profile Id="{$Sid}">

      <KioskModeApp v4:ClassicAppPath="%Program Files%\WindowsApps\%RemoteDesktop%\RdClient.Windows.exe" v4:ClassicAppArguments="--kiosk https://www.contoso.com/ --edge-kiosk-type=fullscreen --kiosk-idle-timeout-minutes=5" />

      <v4:BreakoutSequence Key="Ctrl+A" />

    </Profile>

  </Profiles>

  <Configs>

    <Config>

      <Account>"{$user}"</Account>

      <DefaultProfile Id="{$Sid}" />

    </Config>

  </Configs>

</AssignedAccessConfiguration>

"@

 

$namespaceName="root\cimv2\mdm\dmmap"

$className="MDM_AssignedAccess"

$obj = Get-CimInstance -Namespace $namespaceName -ClassName $className

$obj.Configuration = [System.Net.WebUtility]::HtmlEncode($assignedAccessConfiguration)

Set-CimInstance -CimInstance $obj

 

Any help is appreciated!

1 Reply

  • Artemis23

     

    here is the updated version of your script please check and update if you have further problems

     

    $user = "RemoteDesktopUser"
    $userDesc = "Remote Desktop"
    New-LocalUser -Name $user -NoPassword -AccountNeverExpires -UserMayNotChangePassword -Description $userDesc | Set-LocalUser -PasswordNeverExpires $true
    Add-LocalGroupMember -SID S-1-5-32-545 -Member $user
    $Sid = (Get-LocalUser -Name $user).SID.Value
    
    $assignedAccessConfiguration = @"
    <?xml version="1.0" encoding="utf-8"?>
    <AssignedAccessConfiguration xmlns="http://schemas.microsoft.com/AssignedAccess/2017/config" xmlns:rs5="http://schemas.microsoft.com/AssignedAccess/201810/config" xmlns:v4="http://schemas.microsoft.com/AssignedAccess/2021/config" xmlns:v5="http://schemas.microsoft.com/AssignedAccess/2022/config">
      <Profiles>
        <Profile Id="{$Sid}">
          <KioskModeApp v4:ClassicAppPath="%ProgramFiles%\WindowsApps\%RemoteDesktop%\RdClient.Windows.exe" v4:ClassicAppArguments="--kiosk https://www.contoso.com/ --edge-kiosk-type=fullscreen --kiosk-idle-timeout-minutes=5" />
          <v4:BreakoutSequence Key="Ctrl+A" />
        </Profile>
      </Profiles>
      <Configs>
        <Config>
          <Account>"{$user}"</Account>
          <DefaultProfile Id="{$Sid}" />
        </Config>
      </Configs>
    </AssignedAccessConfiguration>
    "@
    
    # Use the correct namespace
    $namespaceName = "root\Microsoft\Windows\AssignedAccess"
    $className = "AssignedAccessConfiguration"
    
    # Create a new instance if none exists
    $obj = Get-CimInstance -Namespace $namespaceName -ClassName $className -ErrorAction SilentlyContinue
    if (!$obj) {
        $obj = New-CimInstance -Namespace $namespaceName -ClassName $className
    }
    
    # Set the configuration using the appropriate property
    $obj.Xml = $assignedAccessConfiguration
    
    # Save the configuration
    Set-CimInstance -CimInstance $obj