2017-06-29 9 views
0

私はさまざまなディレクトリを検索するために使用できるデータを集約するSQLサーバーを照会するスクリプトを作成しています。フォルダーが存在しない場合は、存在しないパスをコードの最後のテキストファイルに書き込む必要があります。 SQLデータを使って完成したパスの文字列をあらかじめ入力する配列を作成しました。私は入力スティングの問題には、正しい形式ではなく、それが正しくテキスト文書を埋めるの問題ではなかった。それは、存在しないか存在しないフォルダをテキスト文書に埋め込みます。 私はさまざまな設定を試みました。私は配列が私の問題かもしれないと信じていますが、私は現在不安です。次のようにサブディレクトリの存在を確認

エラーは次のとおりです。

Cannot convert value "Walker" to type "System.Int32". Error: "Input string was not in a correct format." 
At \\cottonwood\users\C.B\My Documents\Untitled1.ps1:36 char:115 
+ ... Address)#> + $($Row.'Last Name') + $array[$i] 
+     ~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: (:) [], RuntimeException 
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger 

コードは次のとおりです。パーサは+オペレータがやっていることになっているもので混乱しているよう

$SQLServer = "REDWOOD" #use Server\Instance for named SQL instances! 
$SQLDBName = "MARS" 
$SqlQuery = "select Account, IsActive, [Last Name] FROM vw_loans WHERE (Account NOT IN ('100040A','100041A','100044A','100044B','100044C','100079A','100040A','100041A','100044A','100044B','100044C','100079A','100153B','100413B')) AND LEFT(Account,1)<>'_' AND (Account NOT like '%B%') AND (LoanStatus != 'PRELIM') ORDER BY Account" 

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True" 

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand 
$SqlCmd.CommandText = $SqlQuery 
$SqlCmd.Connection = $SqlConnection 

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter 
$SqlAdapter.SelectCommand = $SqlCmd 

$DataSet = New-Object System.Data.DataSet 
$SqlAdapter.Fill($DataSet) 


$SqlConnection.Close() 

clear 

$DataSet.Tables[0] 

$array = "\I. Originations\Final Originations Package","\II. Servicing\A. Communications", "\II. Servicing\B. Foreclosure Documents","\II. Servicing\C. Bankruptcy Documents", "\II. Servicing\D. Amendments & Extensions", "\II. Servicing\E. Property", "\II. Servicing\F. Previous Servicer Data", "\III. Loan Documents", "\IV. Taxes, Insurance, HOA\HOA", "\IV. Taxes, Insurance, HOA\Insurance","\IV. Taxes, Insurance, HOA\Insurance\PMI","\IV. Taxes, Insurance, HOA\Taxes" 

foreach ($Row in $dataset.Tables[0].Rows) 
{ 

    for($i=0;$i -lt $array.Length; $i++) 
    { 
    if($Row.IsActive -eq $True)  
     { 
       $CorrPath = "U:\Shared\Loan Documents - Active\" + $($Row.Account) + " - " + <#$(Row.Address)#> + $($Row.'Last Name') + $array[$i] 
     }  

    if($Row.IsActive -eq $False) 
     { 
      $CorrPath = "U:\Shared\Loan Documents - Inactive\" + $($Row.Account) + " - " + <#$(Row.Address)#> + $($Row.'Last Name') + $array[$i] 
     } 

    $FileExist = Test-Path $CorrPath 

    If($FileExist -eq $False) 
    {Add-Content $Corrpath -Path "\\cottonwood\users\IT\Missing Folder Location\MissingSubFolders.txt"} 

    } 



} 
+0

あなたはエラーメッセージを取得している場合は、あなたの質問にその完全かつ正確なテキストを含めてください - 多くの場合、とPowerShellでは、メッセージの意味はすぐにはわかりませんが、経験豊富なPowerShellコーダーがメッセージを解読し、エラーを特定することができます。 –

+0

コードを修正してエラーを追加しました。 –

答えて

1

は、私には見えます。それは連結する必要があるときに追加しようとしています。

if($Row.IsActive) { 
    $CorrPath = "U:\Shared\Loan Documents - Active\" + $($Row.Account.ToString()) + " - " + <#$(Row.Address)#> + $($Row.'Last Name'.ToString()) + $array[$i].ToString() 
} else { 
    $CorrPath = "U:\Shared\Loan Documents - Inactive\" + $($Row.Account.ToString()) + " - " + <#$(Row.Address)#> + $($Row.'Last Name'.ToString()) + $array[$i].ToString() 
} 

さもないと、異なるファイル名をフォーマットしてみてください:文字列にすべてを強制的に試してみてください

$CorrPath = "U:\Shared\Loan Documents - Active\{0} - {1}{2}" -f $Row.Account,$Row.'Last Name',$array[$i] 
+0

私はあなたが役に立たないことを推奨した修正を試みました。もしあなたができれば、メッセージを私に指示して、私がさらにお尋ねすることができますか? –

関連する問題