Error: WinRM provisioner & New-SMBShare share names are wrong

Hello all. I am creating deployment scripts for AWS Windows 2016 servers. I have added a script in my packerfile.json that is executed as part of the WinRM provisioner and is supposed to create a series of folders and then create an SMB share for each folder.
When I run the script from the server while logged on it runs perfectly, no issues.
When I run the script as part of the AMI provisioner, WinRM, it creates share names with a prefix and suffix which then causes errors later on when a script must use the share name to finish a task.
Example same code run from Server and WinRM:
New-SMBShare –Name “WFInstall” –Path “D:\TEMPINSTALL” -FullAccess “everyone”
Output when run from the server:
Name = WFInstall
Output when run from WinRM during the AMI bake:
Name = â€Name WFInstall â€Path

It’s not an error and provisioning finishes as expected but the share names are wrong. I don’t believe it’s a problem with elevated privilege because the script also adds local groups and this works fine. Any ideas?

Maybe it is trying to tell you FullAccess for everyone is a bad idea :slight_smile:

I would suspect the issue is with JSON. Have you tried using single quotes?

New-SMBShare –Name ‘WFInstall’ –Path ‘D:\TEMPINSTALL’ -FullAccess ‘everyone’

PS does not need them in this case.


LOL @ FullAccess. That was just my testing use case, and I have granular security set with NTFS (no everyone) so it should work out.
That’s a good idea, I will try the single quotes and see if it makes a difference. I didn’t think it would be the JSON because it’s simply copying the .ps1 file from GitHub to the local drive before it executes but maybe it’s doing some strange things to the file during the copy.

Lets hope it works, and I was hoping you would get a laugh out of my comment :slight_smile:

My thoughts on JSON is that when it executes the script, the double quotes may be confusing things. Just thinking out loud, this certainly is one for “stump the geek”

Nope, the single quotes didn’t work. The output shows that it just adds the single quote to the Name:
Name = â€Name ‘WFInstall’ â€Path


change your json to force UTF-8 encoding, or try to run it through a validator (i.e., google “json validator” if links here are forbidden).

It looks like whatever if using the json file is translating the special characters (specifically the - in this case) to arbitrary trash. Without the code that is being annoying, it is hard to determine what exactly is getting trans-coded improperly.

Also, you may not need the ’ at all, that trash translation can also be coming from the ’ or ", Some markdown sites use “ and ”, which is probably also getting translated incorrectly.