Hi,
I’ve created a custom class based DSC resource and while I don’t see any errors when executing the start-dsc command. The custom resource doesn’t have the intended effect of creating a New-PSDrive.
[DscResource()]
Class CreatePSDrive
{
[DscProperty(Key)]
[string]$Name
[DscProperty(Mandatory)]
[string]$Root
[DscProperty(Mandatory)]
[PSCredential]$Credential
[CreatePSDrive] Get()
{
Write-Verbose $this.Name
Write-Verbose $this.Root
$drive = (Get-PSDrive | ? {$_.Name -eq $this.Name})
if($drive -ne $null)
{
$this.Name = $drive.Name
$this.Root = $drive.Root
}
else
{
$this.Name = $null
$this.Root = $null
}
return $this
}
[void] Set()
{
Write-Verbose $this.Name
Write-Verbose $this.Root
Write-Verbose ($this.Credential).UserName
($this.Name).GetType()
New-PSDrive -Name $this.Name -Root $this.Root -PSProvider FileSystem -Persist -Verbose -Credential $this.Credential
}
[bool] Test()
{
$driveExists = (Get-PSDrive | ? {$_.Name -eq $this.Name})
Write-Verbose $this.Name
Write-Verbose $this.Root
if($driveExists -eq $null)
{
Write-Verbose "PSDrive does not exist"
return $false
}
else
{
Write-Verbose "PSDrive" $this.Name "exists"
return $true
}
}
}
When I’ve run start-dsc I get the following output which indicates the Set ran successfully but when running get-psdrive I cant see the new-psdrive.
2Na&(vS8zLTLFAMx
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, "methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'. VERBOSE: An LCM method call arrived from computer VMNAME with user sid VERBOSE: [VMNAME]: LCM: [ Start Set ] VERBOSE: [VMNAME]: LCM: [ Start Resource ] [[CreatePSDrive]NewDrive] VERBOSE: [VMNAME]: LCM: [ Start Test ] [[CreatePSDrive]NewDrive] VERBOSE: [VMNAME]: [[CreatePSDrive]NewDrive] I VERBOSE: [VMNAME]: [[CreatePSDrive]NewDrive] \\shared_drive\msapp\MSAPP\Repository\Installers VERBOSE: [VMNAME]: [[CreatePSDrive]NewDrive] PSDrive does not exist VERBOSE: [VMNAME]: LCM: [ End Test ] [[CreatePSDrive]NewDrive] in 0.5470 seconds. VERBOSE: [VMNAME]: LCM: [ Start Set ] [[CreatePSDrive]NewDrive] VERBOSE: [VMNAME]: [[CreatePSDrive]NewDrive] I VERBOSE: [VMNAME]: [[CreatePSDrive]NewDrive] \\shared_drive\Repository\Installers VERBOSE: [VMNAME]: [[CreatePSDrive]NewDrive] DOMAIN\username VERBOSE: [VMNAME]: [[CreatePSDrive]NewDrive] Performing the operation "New drive" on target "Name: I Provider: Microsoft.PowerShell.Core\FileSystem Root: \\shared_drive\Repository\Installers". VERBOSE: [VMNAME]: LCM: [ End Set ] [[CreatePSDrive]NewDrive] in 0.3130 seconds. VERBOSE: [VMNAME]: LCM: [ End Resource ] [[CreatePSDrive]NewDrive] VERBOSE: [VMNAME]: LCM: [ End Set ] VERBOSE: [VMNAME]: LCM: [ End Set ] in 1.5420 seconds. VERBOSE: Operation 'Invoke CimMethod' complete. VERBOSE: Time taken for configuration job to complete is 1.78 seconds
If I run the same New-PSdrive command outside of DSC it works fine.
Any pointers you can provide would be greatly appreciated
Thanks
Mubashir