SQL Server Agent calling Powershell with parameters that Powershell can use as variables?
on multi-instance box. how can send powershell current calling server name make powershell scripts dynamic? appears must hard code server name since powershell opens in default directory when executed sql server agent. can machine name through env::machinename property. however, cannot find way current sql server name executing powershell.exe. there way name?
thanks,
mike
looking @ jobs have running on hundreds of servers. use token method.
here's cmdexec job step calls powershell.exe:
c:\windows\system32\windowspowershell\v1.0\powershell.exe -command "c:\windows\script\write-voltodb.ps1 $(escape_squote(srvr))"
i'm calling script named write-voltodb.ps1 script takes parameter for sqlserver
here's first line of script:
param($sqlserver)
the sqlserver name obtained using sql server agent token $(escape_squote(srvr))
keep in mind $(escape_squote(srvr)) not powershell variable though looks one. token described here
http://msdn.microsoft.com/en-us/library/ms175575.aspx
so you'll need to:
1. write script or command take parameter
2. use sql server agent tokens dynamically obtain serverinstance
Windows Server > Windows PowerShell
Comments
Post a Comment