使用Powershell创建子文件夹

使用Powershell创建子文件夹,powershell,Powershell,好的,正在寻求有关Powershell的帮助。我需要在一个目录中的大约200个文件夹中创建一个同名子文件夹。到目前为止,我有: $folder = NewFolderName new-item -type directory -path \\servername\directory\directory\$folder -Force 这可以在所有200个文件夹中创建单个文件夹吗?请尝试以下代码片段: $parent = '\\servername\directory' $folder = 'Ne

好的,正在寻求有关Powershell的帮助。我需要在一个目录中的大约200个文件夹中创建一个同名子文件夹。到目前为止,我有:

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

这可以在所有200个文件夹中创建单个文件夹吗?

请尝试以下代码片段:

$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
    }

在调试之前立即删除风险缓解参数…

请尝试以下代码段:

$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
    }
在调试之前立即删除风险缓解参数