0

I am trying to copy one file from share in my custom dsc script. This code below works great in powershell, but not working in dsc resource.

PS C:\Users\user> $wc = New-Object System.Net.WebClient
PS C:\Users\user> $wc.DownloadFile("\\DC1\Downloads\en_sql_server_2012_enterprise_edition_with_service_pack_2_x64_dvd_
4685849.iso", "C:\SQL2012SP2.iso")

Powershell 4/5 has native commandlets for get files from smb share? Or any variants?

Vadim Seo
  • 41
  • 1
  • 3
  • 1
    Why are you using a `System.Web.NetClient` for downloading from a samba share? Why not just copy the file to the destination? – arco444 Nov 05 '14 at 12:02

2 Answers2

0

As @arco444 alluded to, the way you're doing this is bananas. Why not use Copy-Item?

That aside, I think you would have the problem with Copy-Item as well.

DSC runs under the context of SYSTEM, so you should make sure that your share allows access from the machine account of the machine on which the DSC is to be executed.

Alternatively, you can grant read access to Authenticated Users (which includes all other users as well), or Domain Computers if you're in a domain and want all of the computers to be able to read the contents.

briantist
  • 45,546
  • 6
  • 82
  • 127
0

The Credential parameter in file resource is used to connect to the source - so you can specify credentials for the share.

However make sure that credentials are secured as described in this article - [link] http://blogs.msdn.com/b/powershell/archive/2014/01/31/want-to-secure-credentials-in-windows-powershell-desired-state-configuration.aspx

Nana Lakshmanan
  • 741
  • 3
  • 6