Powershell DSC - 将文件解压缩到远程目标

时间:2018-06-06 08:03:21

标签: powershell automation hyper-v powershell-dsc

我的目标是创建一个 Powershell DSC 配置,将文件从本地计算机解压缩到Hyper-V Win10 VM 上的远程目录(I&# 39;已经共享了该目标文件夹)。但是,现在,我仍然有一些问题要在.ps1中插入VM凭据。这是我的代码:

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'
    }
}

}

有人可以建议我在Powershell脚本中插入 Windows凭据(远程机器)吗?

感谢您的时间......希望您能提供帮助!

1 个答案:

答案 0 :(得分:0)

您必须在DSC配置中使用凭证。 下面的文档将帮助您实现它。

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

下面的

是一个在DSC配置中使用凭证的小例子。

configuration FileCopy
{
Param(
    [PSCredential]$Credential
)
    node localhost
    {
        File CopyFile{
            Ensure = 'Present'
            DestinationPath = '\\server\share'
            SourcePath = 'c:\sourcepath'
            PsDscRunAsCredential = $Credential
        }
    }
}
相关问题