I am writing a PowerShell script and I need to create a directory in C:\Users
My script is located on the desktop.
My line of script to create the directory is this:
New-Item -ItemType "directory" -Force -Path "C:Users\username\scripts\documents"
It instead creates the directory:
C:\Users\username\Desktop\Users\username\scripts\documents
How can I make the new directory directly in C:\Users?
You are missing a backslash
\after the path root (the drive letter):See also: https://learn.microsoft.com/en-us/dotnet/api/system.io.path.ispathrooted?view=net-5.0
(I did not include the
[System.IO.Path]::IsPathFullyQualified()call in the linked example, because it is not included in Windows PowerShell 5.1)