PowerShell / PSDscResources

MIT License
129 stars 53 forks source link

Script Resource "No user exists" #190

Open DanteNahuel opened 4 years ago

DanteNahuel commented 4 years ago

Details of the scenario you tried and the problem that is occurring

I'm using a Script resource to run a cmd that installs software. The first run always, always returns an error "No user exists". After the first run, dsc auto corrects the issue and it works without a problem and the node gets in compliance.

Verbose logs showing the problem

PS>TerminatingError(install-univ-v5.cmd): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No users exist. Please set up a user."

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Script software
        {
            DependsOn = "[PendingReboot]AfterDomainJoin"
            SetScript =
            {
                # Start logging the actions 
                Start-Transcript -Path C:\Temp\install.txt -Append -Force
                New-Item -Path "C:\Temp" -Name "software" -ItemType "directory" -Force
                Copy-Item -Path "\\network\MSI$\software\*" -Destination "C:\Temp\software\" -Recurse -Force
                Set-Location "C:\Temp\software"
                & "C:\Temp\software\install.cmd" 
                Stop-Transcript
            }

            TestScript =
            {
                $software = "Software Service";
                $service = Get-Service -DisplayName $software -ErrorAction SilentlyContinue

                    If ($null -eq $service)
                    {
                        Write-Verbose "Software is not installed"     
                            return $False 
                    }
                        Else
                    {
                        Write-Verbose "Software is Installed"
                        Return $True

                    }
            }

        GetScript = { @{ $software=  Get-Service -DisplayName "software Service" -ErrorAction SilentlyContinue} }
        PsDscRunAsCredential = $SecureCred      
        }