2012-08-08 191 views
1

我想将路径变量 - > param([string] $ w)传递到另一个参数中,该参数将路径存储在power shell脚本中。然后使用另一个批处理文件调用此Power Shell脚本。我未能通过$这是完成完整路径的文件夹名称。请建议我在此使用批处理文件将路径参数传递到Power Shell脚本

$FilePath = "C:\Root\Main\Subfolder\param ([string]$w)\Table\" 
$FileExists = Test-Path $FilePath 

    If ($FileExists -eq $True) 
    { Get-ChildItem -path C:\Root\Main\Subfolder\param ([string]$w)\Table\ -Recurse -Filter *.sql | 
     ` Sort-Object -Property DirectoryName -Desc | ` 
     Foreach-Object -Process {$_.FullName } |ForEach-Object {sqlcmd -i $_} 
    } 

    Else {Write-Host "No file at this location"} 

解决方案这是我的批处理文件命令行

PowerShell.Exe -File C:\Users\AZ\Desktop\PowerShell\untitled7.ps1 "Payment" 

回答

1

尝试把这个在你的脚本的顶部:

param(
     [Parameter(
        Mandatory=$true, 
        Position=0, 
        HelpMessage='Set path variable')] 
     [string] $w 
) 

替换:

param ([string]$w) 

附:

$w 

它出现在您的脚本中。

+0

嗨@nimizen,非常感谢您的解决方案。它完美的作品。祝你今天愉快! – 2012-08-08 09:35:07

相关问题