Powershell Xml 文件 >> 创建文件夹



我想从 xml文件的一部分中创建一个带有powershell中xml文件名的文件夹。

我找到了类似的东西,但是不是文件夹,而是一个txt文件:

$xml = [xml](Get-Content c:tempconfig.xml)
$xml.config.compare.source
$xml.config.compare.parameters.parameter[0]
$xml.config.compare.source >> c:tempoutput.txt

我不能用它来创建一个文件夹吗?

[xml]$xml = @"
<config>
    <compare>
        <original name="Test123" />
    </compare>
</config>
"@
# Get value from the XML
Write-Host $xml.config.compare.original.name
$newDirectory = Join-Path -Path "C:Users" -ChildPath $env:USERNAME
Write-Host $newDirectory
$newDirectory = Join-Path -Path $newDirectory -ChildPath $xml.config.compare.original.name
Write-Host $newDirectory
# Create a folder using one of the values
New-Item -Path $newDirectory -ItemType Directory

较短答案

$NewDir = Join-Path -Path "C:Users" -ChildPath $env:USERNAME | 
New-Item -Path $NewDir -Name $xml.config.compare.original.name -ItemType Directory

另外,由于C: Users Currentuser AlreAy的变量以$ home的形式存在:

New-Item -Path $NewDir -Name $xml.config.compare.original.name -ItemType Directory

最新更新