Author Posts

April 4, 2017 at 5:26 pm

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

April 4, 2017 at 6:30 pm

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