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

Welcome Forums General PowerShell Q&A Error: WinRM provisioner & New-SMBShare share names are wrong

Viewing 5 reply threads
  • Author
    Posts
    • #204675
      Participant
      Topics: 2
      Replies: 5
      Points: 29
      Rank: Member

      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?

    • #204702
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

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

      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.

       

    • #204705
      Participant
      Topics: 2
      Replies: 5
      Points: 29
      Rank: Member

      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.

      • This reply was modified 3 months, 2 weeks ago by Mark_ODO.
    • #204714
      Participant
      Topics: 6
      Replies: 93
      Points: 428
      Helping Hand
      Rank: Contributor

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

      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”

    • #204912
      Participant
      Topics: 2
      Replies: 5
      Points: 29
      Rank: Member

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

       

    • #204951
      Participant
      Topics: 1
      Replies: 20
      Points: 109
      Helping Hand
      Rank: Participant

      change your json to force UTF-8 encoding, or try to run it through a validator (i.e. https://jsonlint.com, 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.

      EDIT:
      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.

      • This reply was modified 3 months, 1 week ago by p42p0wd3r.
Viewing 5 reply threads
  • The topic ‘Error: WinRM provisioner & New-SMBShare share names are wrong’ is closed to new replies.