• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2286
  • Last Modified:

powershell script to create folder remotely

Hi,

i need powershell script or other to create remotely 2 folder like this : c:\folder\test in many server.

I have a txt file with the list of server with one server per line like this:

server1
server2
server3
.......

thanks
0
cawasaki
Asked:
cawasaki
1 Solution
 
Dale HarrisCommented:
Do you get any errors when you type something like this:

new-item -type directory -path \\server1\c$\folder\test

If UNC is possible for you, then reading the list of servers or IPs is pretty straightforward:

gc "Servers.txt" | %{new-item -type directory -path "\\$_\c$\folder\test"}

HTH,

Dale Harris
0
 
neothwinCommented:
Please try with the following:
Please note: if you run in batch file, please replace % with %%. e.g. change %a to %%a

C:\>for /f %a in (Servers.txt) do (md \\%a\c$\Folder & md \\%a\c$\Folder\Test)

rgds,
0
 
cawasakiAuthor Commented:
Hi Dale

All my server is 2008 server with powershell installed and UNC is possible.

for your command line : gc "Servers.txt", are you sure for gc is correct. its not get .?

thanks
0
 
QlemoC++ DeveloperCommented:
gc is the alias for get-content, so http:#a36936273 is correct.

You can also use mkdir instead of new-item -type Directory, as that is more straightforward (but less PowerShellish).
0
 
cawasakiAuthor Commented:
Work perfect thanks
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now