vmware / dscr-for-vmware

The Repository contains Microsoft PowerShell Desired State Configuration (DSC) Resources for managing VC and ESXi settings.
Other
139 stars 41 forks source link

Test-VmwDscConfiguration doesn't work #323

Closed tralalas closed 3 years ago

tralalas commented 3 years ago

Hello, I'm trying to test the VMware.vSphereDSC and VMware.PSDesiredStateConfiguration. I have created the following config file as per the examples from https://github.com/vmware/dscr-for-vmware/blob/master/VMware.PSDesiredStateConfiguration.md

dsc_test01.ps1 Param( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [string] $Server,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
$Credential

)

Configuration Datacenter_Config {

Param(
    [string]
    $Server,

    [System.Management.Automation.PSCredential]
    $Credential
)

Import-DscResource -ModuleName VMware.vSphereDSC

Node localhost {
    Datacenter MyDatacenter {
        Server = $Server
        Credential = $Credential
        Name = 'MyDatacenter'
        Location = ''
        Ensure = 'Present'
    }
}

}

after that from a powershell with adminrights I'm running the following: 1) to provide the creds of the vcenter $Credential = Get-Credential 2)to create the new vmwdsc object with the parameters $newVmwDscConfigParams = @{ Path = '.\DSC_test01.ps1' Parameters = @{ Server = 'myvcenterfqdn' Credential = $Credential } } 3)$dscConfiguration = New-VmwDscConfiguration @newVmwDscConfigParams 4)trying to test Test-VmwDscConfiguration -Configuration $dscConfiguration I get the following error: Select-Object : Property "InvokeResult" cannot be found. At C:\Program Files\WindowsPowerShell\Modules\VMware.PSDesiredStateConfiguration\1.0.0.16\Functions\Public\Test-VmwDscC onfiguration.ps1:76 char:35

if I run the Start-VmwDscConfiguration -Configuration $dscConfiguration everything is fine MyDatacenter is created without any issues.

I have tried to run it from both ps 5.1 and 7.0 but in 7.0 I get an error that is not able to find the modules in C:\Program which I guess is due to the known error of spaces.

Any idea why I get that error ?

SimeonGerginov commented 3 years ago

I've tested it on both PowerShell 5.1 and 7.0. On PowerShell 7.0 everything works as expected. On PowerShell 5.1 if you call the Test-VmwDscConfiguration cmdlet with the Detailed parameter like this:

Test-VmwDscConfiguration -Configuration $dscConfiguration -Detailed

Everything also works as expected. The problem only arises when the Detailed parameter is not passed on PowerShell 5.1.

Till we address this issue, you can either use PowerShell 7.0 in a folder with no spaces or pass the the Detailed parameter on PowerShell 5.1.

On PowerShell 7.0 you can use the $env:PSModulePath variable and add to it a folder where you have the modules like this:

$env:PSModulePath += ';<Path to folder with the VMware modules>'
SimeonGerginov commented 3 years ago

The bug was fixed with PR #324, so it should work as expected with the latest version of the module.

tralalas commented 3 years ago

Hi Simeon, Ok thank you so I was missing the -detailed parameter.

Thank you, Sorin

On Wed, Apr 28, 2021 at 6:40 PM SimeonGerginov @.***> wrote:

The bug was fixed with PR #324 https://github.com/vmware/dscr-for-vmware/pull/324, so it should work as expected with the latest version of the module.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vmware/dscr-for-vmware/issues/323#issuecomment-828604765, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMYV5ETIKYO75GOTMH6KBN3TLA3BHANCNFSM43XCOCBA .