Sql server 如何将列记录放入列表中
我有两个PowerShell脚本,我想合并我有一个用于进行数据转储Sql server 如何将列记录放入列表中,sql-server,powershell,Sql Server,Powershell,我有两个PowerShell脚本,我想合并我有一个用于进行数据转储 这一个用于复制图片,我手动将路径粘贴到查询中从PathOnDrive获得的$imagesList $targetFolderName = "C:\test" $sourceFolderName = "F:\App\ISTAB.Data\pictures_global\P" $imagesList = ( "F:\App\ISTAB.Data\pictures\P\122\338\7\1326647", "F:\App\IST
这一个用于复制图片,我手动将路径粘贴到查询中从PathOnDrive获得的
$imagesList
$targetFolderName = "C:\test"
$sourceFolderName = "F:\App\ISTAB.Data\pictures_global\P"
$imagesList = (
"F:\App\ISTAB.Data\pictures\P\122\338\7\1326647",
"F:\App\ISTAB.Data\pictures\P\179\924\0\1678117"
)
foreach ($itemToCopy in $imagesList)
{
$targetPathAndFile = $itemToCopy.Replace( $sourceFolderName , $targetFolderName )
$targetfolder = Split-Path $targetPathAndFile -Parent
if (!(Test-Path $targetfolder -PathType Container)) {
New-Item -Path $targetfolder -ItemType Directory -Force
}
Copy-Item -Path $itemToCopy -Destination $targetPathAndFile
}
因此,我的问题是如何将PathHandrive列中的所有记录自动输入我的
$imagesList
,我找到了它
foreach ($Columns in $DataSet.Tables[0].Rows) {
$imagesList = "$($Columns.PathOnDrive)"
write-Output "$($imagesList)"
$targetFolderName = "D:\DataFeed\Pictures\Parts"
$sourceFolderName = "F:\App\ISTAB.Data\pictures_global\P"
foreach ($itemToCopy in $imagesList)
{
$targetPathAndFile = $itemToCopy.Replace( $sourceFolderName , $targetFolderName )
$targetfolder = Split-Path $targetPathAndFile -Parent
if (!(Test-Path $targetfolder -PathType Container)) {
New-Item -Path $targetfolder -ItemType Directory -Force
}
Copy-Item -Path $itemToCopy -Destination $targetPathAndFile
}
}
您能否提供
$query
中的示例表?我假设您的SQL表有路径名。与其尝试使用T-SQL操作字符串,不如返回数据并在Powershell中操作它。这要容易得多。T-SQL只是在字符串操作方面不够强大。Powershell可以使用所有.NET类和方法。您可以使用String.Insert
插入斜杠,或者使用正则表达式提取所需的字符串部分,而不是所有这些子字符串操作
foreach ($Columns in $DataSet.Tables[0].Rows) {
$imagesList = "$($Columns.PathOnDrive)"
write-Output "$($imagesList)"
$targetFolderName = "D:\DataFeed\Pictures\Parts"
$sourceFolderName = "F:\App\ISTAB.Data\pictures_global\P"
foreach ($itemToCopy in $imagesList)
{
$targetPathAndFile = $itemToCopy.Replace( $sourceFolderName , $targetFolderName )
$targetfolder = Split-Path $targetPathAndFile -Parent
if (!(Test-Path $targetfolder -PathType Container)) {
New-Item -Path $targetfolder -ItemType Directory -Force
}
Copy-Item -Path $itemToCopy -Destination $targetPathAndFile
}
}