Create Subfolders using Powershell

nosupport2020

Ok, looking for some assistance with Powershell. I need to create a subfolder with the same name in about 200 folders in a directory. So far I have this:

$folder = NewFolderName
new-item -type directory -path \\servername\directory\directory\$folder -Force

Will this work to create the single folder in all 200 folders?

JosefZ

Try the following code snippet:

$parent = '\\servername\directory'
$folder = 'NewFolderName'
Get-ChildItem -Path $parent -Directory |
    ForEach-Object {
        New-Item -WhatIf -Type Directory -Path (
            Join-Path -Path $_.FullName -ChildPath $folder) -Force
    }

Remove the risk mitigation parameter -WhatIf no sooner than debugged…

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I Compare Two Folders and Create Missing Subfolders in PowerShell

Batch or PowerShell Script Needed to Create Subfolders within Multiple Root Folders

How to extract all zip files in subfolders in same folder using powershell

How to find all the empty subfolders inside the folder using powershell?

Rename bulk files with given name, in directory and subfolders using PowerShell

How to edit file extensions across multiple subfolders using powershell or other

Split folder having files into 50 MB subfolders using bat or powershell

Copy specific type files from subfolders using a Powershell script

Create HDCluster using powershell

PowerShell error in renaming of subfolders

Loop through subfolders in powershell

Create multiple subfolders in specific subfolders in Python

Create a firewall rule using powershell

Create table using HTML in Powershell

Create a folder structure using PowerShell

How to create a Function using Powershell

create a log file using powershell

Create Shortcut using PowerShell Script

Using PowerShell to Create Zip Files

Powershell delete subfolders with a specific name

PowerShell script to print all subfolders

Can I rename files in subfolders based on.CSV file using Powershell

Using powershell to merge PDFs in multiple subfolders with pdftk and then delete original PDF files

How to remove all access rules from folder AND all subfolders using PowerShell?

Using .gitignore with *.pyc in subfolders

Create the same subfolders in another folder

How to create a JUnit TemporaryFolder with subfolders

IntelliJ: create gradle modules in subfolders

How to create subfolders in git branch?