Help required with PS script...


wonder if guys can help. have powershell script extracts jobs specific instance of sql server , outputs them directory. part of script works fine. in 2nd part of script, want run in of scripts directory instance of sql server , it's @ stage script failing. script part of procedure follows:

-------------------------------------------------------------------

 

foreach ($f in get-childitem -path "c:\sqljobs\" -filter *.sql | sort-object)

{

$out = "c:\sqljobs\output\" + $f.name.split(".")[0] + ".txt" ; "servername" -inputfile $f.fullname | format-table | out-file -filepath  $out

}

-------------------------------------------------------------------

i have tried adding -database "databasename" command , directories exist. bit stumped, jobs output fine, script fails following error:

------------------------------------------------------------------- 

the term 'invoke-sqlcmd' not recognized name of cmdlet, function, script file, or operable program. check spelling of name,

or if path included, verify path correct , try again.

at c:\users\kitchenaadmin\documents\directoryname - jobs\script_jobs.ps1:30 char:17

+ invoke-sqlcmd <<<< –serverinstance "servername" -inputfile $f.fullname | format-table | out-file -filepath $out

+ categoryinfo : objectnotfound: (invoke-sqlcmd:string) [], commandnotfoundexception

+ fullyqualifiederrorid : commandnotfoundexception

------------------------------------------------------------------- 

i know end being straight forward having had head burried in while needs fresh pair of eyes point out obvious.

any info appreciated, cheers!

 

 

 

 


------------------------------------------------------------------- 

invoke-sqlcmd –serverinstance

invoke-sqlcmd special cmdlet wich avaiable in sql powershell console.
guess have load module / psssnapin wich holds sql cmdlets in scripts!
http://social.technet.microsoft.com/forums/en-au/winserverpowershell/thread/309da0e1-e7eb-41a3-830d-3b14676635ee

add-pssnapin sqlservercmdletsnapin100

get-help about_modules
get-help about_pssnapins

 


please click “mark answer” if post answers question , click "vote help" if post helps you. bitte markiere hilfreiche beiträge von mir als "hilfreich" und beiträge die deine frage ganz oder teilweise beantwortet haben als "antwort". das wäre nett :-)) powershell blog http://www.admin-source.info



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS