打印Hello World ,Hello theDataDigger
writeLog ' Hello World'
$Name = "theDataDigger"
writeLog 'Hello $Name'
变量:这里可以是一个字符串,可以是一个SQL语句,可以是一个SQL语句的执行结果
所有的变量加$
$sql_Specific= "select SolutionID, SolutionName, TrustID, AssetPoolID from Cube.view_VirtualSolution where SolutionID in (3119,3120,3121,3122,3111)"
字符串连接:这里调用了1个方法,传递了3个参数,其中第3个里面有3个值,最终会链接在一起打印出来
updateSolutionStatus $SolutionID "CalculationError" ("方案[", $SolutionID, "],更新现金流模型任务[", $taskCode1, "]出错:", "$result1") -join
使用execDataTable来执行SQL语句
$table = execDataTable $sql_Specific $count = $table.Count -- 查询语句中给了4个SolutionID,那么这里count为4
循环,$table 相当于1个列表,里面有4个字典row
foreach($row in $table){ $counter+=1 $SolutionID = $row['SolutionID'] $TrustID = $row['TrustID'] $AssetPoolID = $row['AssetPoolID'] $SolutionName = $row['SolutionName']
方法:
function theDataDigger(){}
PowerShell 链接数据库:数据库基本信息
$Database = ' ' -- 如填 theDataDigger $Server = ' ' -- 如填 ".MSSQL" $SqlConn= New-Object System.Data.SqlClient.SqlConnection $SqlConn="Data Source=$Server;Initial Catalog=$Database;Integrated Security=SSPI;"
PowerShell 链接数据库:数据库链接操作
-- 打开数据库链接 $SqlConn.open() -- 实例化一个SqlCmd对象 $SqlCmd=New-Object System.Data.SqlClient.SqlCommand -- 之前实例化了一个SqlConn对象,这个对象附带了链接数据的基本信息 $SqlCmd.connection=$SqlConn -- $queryStr="select * from theDataDigger" $SqlCmd.commandtext=$queryStr $SqlCmd.CommandTimeout=0; --实例化一个SqlAdapterd对象 $SqlAdapter=New-Object System.Data.SqlClient.SqlDataAdapter -- 把SqlCmd附带的信息给SqlAdapter $SqlAdapter.SelectCommad=$SqlCmd -- 关闭数据库链接 $set=New-Object Data.DataSet $tables_Count=$SqlAdapter.Fill($set) $SqlConn.close()
调用Task
$result1=E:ClientTaskProcessClient.exe $taskCode1 $appDomain $taskType $sessionVariables1 if(!("$result1".Endswith("[Completed]."))){ writeLog "运行更新现金流模型任务异常,$result1" updateSolutionStatus $SolutionID "CalculationError" ("方案[", $SolutionID, "],更新现金流模型任务[", $taskCode1, "]出错:", "$result1") -join continue }
Task基本信息
$appDomain="Task" $taskType="Task" $taskCode1 = "InvestSuite_UpdateCashflowModel"