How to map a network drive with winget configuration file

37 Views Asked by At

I'm writing a winget configuration file (Link) with a lot of actions (Install apps, set env var, set registry, set pc configuration, clone repos, ...). I found no easy way to map a network drive.

I try to set registry keys (Link) and this is working (after pc restart).

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2

properties:
  configurationVersion: 0.2.0
  resources:
    - resource: PSDscResources/Registry
      directives:
        description: Map network drive H
      settings:
        Key: 'HKEY_CURRENT_USER\Network\H'
        Ensure: Present
        ValueName: RemotePath
        ValueType: String
        ValueData: \\my_network_path
        Force: True
    - resource: PSDscResources/Registry
      directives:
        description: Map network drive H
      settings:
        Key: 'HKEY_CURRENT_USER\Network\H'
        Ensure: Present
        ValueName: ConnectFlags
        ValueType: DWord 
        ValueData: 0

But isn't there an easier way to map a network drive by a winget configuration file? I have not been able to execute the powershell command New-PsDrive directly in the configuration file (is that even possible?) and have not found a suitable dsc resource package.

Many thanks for your help.

1

There are 1 best solutions below

0
shengstm On

I found one solution to use the DscResource Script:

properties:
  configurationVersion: 0.2.0
  resources:
    - resource: PSDscResources/Script
      directives:
        description: Run script
      settings:
        GetScript: {}
        SetScript: |
          New-PSDrive -Name "N" -PSProvider FileSystem -Root "\\ner91a0002.niehl.ford.com\eese_eu\hil" -Persist -Scope Global
        TestScript: |
          Test-Path N:

Is there any better solution?