Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要使用PowerShell从以下代码中的文本文件中读取数组内容_Powershell - Fatal编程技术网

需要使用PowerShell从以下代码中的文本文件中读取数组内容

需要使用PowerShell从以下代码中的文本文件中读取数组内容,powershell,Powershell,我需要从文本文件中读取管理员、用户等。这段代码用于创建文件夹结构,我想从文本文件中读取文件夹名称 @('Admin', 'user', 'server') | ForEach-Object { New-Item (Join-Path 'D:\test3\LV2\7212\win10\x64\' $_) -ItemType Directory -force } @('ABC3D_X00-00','WXY3Z_X01-00') | ForEach-Object { New-

我需要从文本文件中读取管理员、用户等。这段代码用于创建文件夹结构,我想从文本文件中读取文件夹名称

@('Admin', 'user', 'server') | ForEach-Object {
    New-Item (Join-Path 'D:\test3\LV2\7212\win10\x64\' $_) -ItemType Directory -force
    }

@('ABC3D_X00-00','WXY3Z_X01-00') | ForEach-Object {
    New-Item (Join-Path 'D:\test3\LV2\7212\win10\x64\audio' $_) -ItemType Directory -force
    }
您有一个名为“stuff.txt”的文件。该文件包含以下内容:

Admin
user
server
在与“stuff.txt”相同的目录中,有一个名为“make.ps1”的脚本,其中包含:

Param($ParentDirectory)
$folder_names = $(gc -Path .\stuff.txt)
foreach ($folder_name in $folder_names ) {
    New-Item -Path $ParentDirectory -Name $folder_name -ItemType Folder
}
然后调用传入父目录的脚本:

C:\> make.ps1 -ParentDirectory '...'

如果您不想将其作为脚本来执行,只需将$ParentDirectory名称设置为常规旧变量,并将其指定为起始目录的路径。

也许您可以进一步扩展您的问题?现在你没有告诉我们你已经尝试了什么。此外,通常情况下,不必提及标题就把问题说清楚是一个好习惯,即使这意味着有点重复,因为这确实有助于人们更快地理解你的目标。你发布的代码和你提出的问题完全无关。为了从文本文件中读取,您需要。我建议你重新措辞你的问题,这样它就可以传达一些额外的信息。嗨,维维克,我刚刚试着获取内容和一些修改,现在可以了,谢谢