开发者

Run tdpsql command from powershell

开发者 https://www.devze.com 2023-02-28 21:14 出处:网络
I have a script that requires 3 mandatory input parameters that will be used to run the backupcommand for tdpsql.

I have a script that requires 3 mandatory input parameters that will be used to run the backup command for tdpsql.

  1. type (FULL, DIFF or LOG)
  2. SQLServerinstancename
  3. Database (SYSTEM, ALL, )

Within the powershell script I have the following line

$cmd = "C:\Progra~1\Tivoli\TSM\TDPSql\tdpsqlc.exe backup " + $idatabase + " " + $action + " " + $parameter + " /LOGFILE=" + $logdir + $logfile + "" $tdpsqlexe - The tdpsqlc exe.
$idatabase - Database name 
$action = FULL\DIFF\LOG
$parameter = /sqlserver=TCP:" + $sqlserverinstance + " /SQLAUTH=INT /TSMOPTFile='" + $dsmoptfilename + "' /EXCLUDEDB=" + $exclude

& $cmd

When I echo the command it reports out what I use to run it using powershell command line but when I try to run it from Powershell with the & it fails with the following

The term

C:\Progra~1\Tivoli\TSM\TDPSql\tdpsqlc.exe backup master FULL /sqlserver=TCP: /SQLAUT H=INT /TSMOPTFile=C:\Progra~1\Tivoli\TSM\TDPSql\dsm.opt /EXCLUDEDB=tempdb /LOGFILE=<logfile>

is not recognized as the name of a cmdlet, function, script file, or operable program.Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At TDPSQLBackup.ps1:166 char:6 + & <<<< $cmd >> test2.txt + CategoryInfo : ObjectNotFound: (C:\Progra~1\Tiv...forsqlimran.txt:String) [], CommandNotFoundEx开发者_如何学编程ception + FullyQualifiedErrorId : CommandNotFoundException

Any help will be really appreciated.


You might try Invoke-Expression $cmd instead of & $cmd.


Yes better use Invoke-Expression, but if you still want to use & you can do it in this way.

$cmd = "C:\Windows\System32\notepad.exe"
$params = "C:\temp\file.txt"

& $cmd $params

Using a var for program file ans a var for parameters.


Instead of running a batch command you'd better try Powershell cmdlets as follow

import-module "C:\Program Files\Tivoli\Flashcopymanager\fmmodulemmc.dll"
import-module "C:\Program Files\Tivoli\Flashcopymanager\fmmoduleSQL.dll"

$startTime = get-date
Backup-DpSqlComponent -Name AdventureWorks2012 -BackupDestination TSM -BackupMethod Legacy -Full
$endTime = get-date

$activity = Get-FcmMmcActivity -StartTime $startTime -EndTime $endTime
$activity

Reference link http://www-01.ibm.com/support/docview.wss?uid=swg21974345

0

精彩评论

暂无评论...
验证码 换一张
取 消