New-item with $ in the script

Welcome Forums General PowerShell Q&A New-item with $ in the script

This topic contains 1 reply, has 1 voice, and was last updated by

2 years, 1 month ago.

  • Author
  • #67888

    Topics: 5
    Replies: 11
    Points: 0
    Rank: Member

    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

    Topics: 5
    Replies: 11
    Points: 0
    Rank: Member

    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

The topic ‘New-item with $ in the script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort