New-item with $ in the script

This topic contains 1 reply, has 1 voice, and was last updated by  Goldy 7 months, 3 weeks ago.

  • Author
    Posts
  • #67888

    Goldy
    Participant

    So i'm racking my brain here..

    I have a function doing several things, but I want to focus on the piece that is racking my brains.

    For example

    Function {

    ##assume this
    $server = "server01"
    $share = "sharetest$"

    $udpath = "\\" + $server + "\" + $share + "test1234"
    new-item -path $udpath -itemtype directory -force

    }

    I cannot figure out for the life of me why i'm getting this. If I take the share outside of the script like this
    new-item \\server\share1$\ud01 -itemtype directory -force

    new-item : The path is not of a legal form.
    At C:\powershell\script.ps1:42 char:1
    + new-item -path $udpath -itemtype directory -force
    + CategoryInfo : InvalidArgument: (\\server\share$:String) [New-Item], ArgumentException
    + FullyQualifiedErrorId : CreateDirectoryArgumentError,Microsoft.PowerShell.Commands.NewItemCommand

  • #67894

    Goldy
    Participant

    This has been solved, the actually problem was the share wasn't provisioned fast enough.. I put a sleep statement in there and all is good

You must be logged in to reply to this topic.