2012-08-08 105 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

相關問題