0

My goal is to create a Powershell DSC configuration to unzip a file - from my local computer - to a remote directory on a Hyper-V Win10 VM (I've already shared that destination folder). But, right now, I still have some problem to insert the VM credentials inside the .ps1. This is my code:

Configuration CopyTest {

Node 'localhost'
{
        User Admin
    {
        UserName = "Admin"
        Password = "Password"
        Ensure = "Present"
    }

    Archive ArchiveExample {
        Ensure = 'Present'
        Path = 'C:\Users\myuser\Documents\test.zip'
        Destination = '\\DESKTOP-HEFLNJ6\destination'
    }
}

}

Can anyone suggest me a way to insert the Windows credentials (of the remote machine) inside the Powershell script?

Thanks for your time...hope you can help!

Dandelion
  • 61
  • 2
  • 7

1 Answers1

0

you will have to use credential in you DSC configuration. Below documentations will help you to achieve it.

https://learn.microsoft.com/en-us/powershell/dsc/runasuser

below is a small example which uses credential in a DSC configuration.

configuration FileCopy
{
Param(
    [PSCredential]$Credential
)
    node localhost
    {
        File CopyFile{
            Ensure = 'Present'
            DestinationPath = '\\server\share'
            SourcePath = 'c:\sourcepath'
            PsDscRunAsCredential = $Credential
        }
    }
}
Prasoon Karunan V
  • 2,916
  • 2
  • 12
  • 26