Unable to disable sconfig at startup using ansible

I am creating the module to disable sconfig at startup for allusers on servercore version. I am running the below code:

#!powershell

# Copyright: (c) 2024, MyName

#AnsibleRequires -CSharpUtil Ansible.Basic

$spec = @{
   options = @{}
     supports_check_mode = $true
}

$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)

$checkMode = $module.CheckMode

try {
#Get the information if server is 'server core' version
$servercore = (Get-ItemProperty -Path 'HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion').InstallationType -eq 'Server Core'
    if ($servercore) {
        # Check sconfig autolaunch status
        $sconfig = Get-SConfig -ErrorAction SilentlyContinue
        $sconfig = $sconfig.AutoLaunch
        
        if ($sconfig) {
            # If sconfig autolaunch status is set to true then change the status to false
            Set-SConfig -AutoLaunch $false -AllUsers -WhatIf:$checkMode
            $module.Result.message = "SConfig AutoLaunch has been set to false."
            $module.Result.changed = $true
        }
        else {
            $module.Result.message = "SConfig AutoLaunch has already been set to false."
        }
    }
   else {
        $module.Result.message = "Server is not server core version"      
    }
}
catch {
  # Handle the errors while fetching server core version informationn
  $module.FailJson("An error occurred while fetching the sconfig information: $_")
}

$module.ExitJson()

Now, let me explain the problem. If I go to directly on the server, it works perfectly fine. However when I run via ansible playbook. I get the below error:

"msg": "An error occurred while fetching the sconfig information: Cannot bind argument to 
parameter 'Path' because it is null.[0].Exception.Message"

It seems that problem is lying with:

(Get-SConfig).AutoLaunch

This command gives output without any error. Since ansible uses winrm so I thought to use below command locally on server:

Invoke-Command {Get-SConfig} -ComputerName $env:ComputerName

It gives the same error ‘cannot bind the parameter’ but also gives output. If I use -ErrorAction ‘SilentlyContinue’, it suppresses the error so I only get the output.
In the error it refers to the ‘path’ that is at line number 176 of sconfig.psm1 file located under C:WindowsSystem32WindowsPowerShellv1.0ModulesMicrosoft.ServeCore.SConfig2.0.0.0. I am attaching the screenshot as well. In the above powershell script, even if I use ErrorAction ‘SilentlyContinue’. It doesn’t work. Not sure what is happening. I have tried this command in server Desktop exp. version by removing ‘server core’ check, it has same issue there also.

One more important aspect. If I remove try catch block in above script on either of the server version ‘servercore or desktop exp’, it works perfectly fine. I am using it on my office system but I have tested it on my personal lab with server core version, it has same result. I downloaded the servercore module but same issue. Please help me to resolve this issue. Let me know if anyone needs any further information.

Thanks

Jatinder Pal Singh (JPS)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật