我正在寻找powershell最快和最小的代码,以便在包含子文件夹的文件夹中查找应用程序。配置文件。
当应用程序。找到配置文件后,它将调用我的函数。
有什么建议吗?
注释:代码的小格式修复
快速查找文件夹中的文件
我正在寻找powershell最快和最小的代码,以便在包含子文件夹的文件夹中查找应用程序。配置文件。
当应用程序。找到配置文件后,它将调用我的函数。有什么建议吗?
我下面的代码只是
应用程序/web。配置
所以我缺少的是一个函数,它可以在目录中进行搜索,并找到一个
应用程序。配置
文件是。
所以让我们说
C:/temp
应进行搜索。在这里我们有
C:/temp/folder1/app.config
C:/temp/folder2/subfolder1/app.config
这将产生两个结果。所以我下面的函数需要调用两次。
param(
$XmlPath,
$XdtPath
)
function XmlDocTransform($xml, $xdt)
{
if (!$xml -or !(Test-Path -path $xml -PathType Leaf)) {
throw "File not found. $xml";
}
if (!$xdt -or !(Test-Path -path $xdt -PathType Leaf)) {
throw "File not found. $xdt";
}
$scriptPath = (Get-Variable MyInvocation -Scope 1).Value.InvocationName | split-path -parent
Add-Type -LiteralPath "$scriptPath\Microsoft.Web.XmlTransform.dll"
$xmldoc = New-Object Microsoft.Web.XmlTransform.XmlTransformableDocument;
$xmldoc.PreserveWhitespace = $true
$xmldoc.Load($xml);
$transf = New-Object Microsoft.Web.XmlTransform.XmlTransformation($xdt);
if ($transf.Apply($xmldoc) -eq $false)
{
throw "Transformation failed."
}
$xmldoc.Save($xml);
}
XmlDocTransform $XmlPath $XdtPath