July 28, 2018 at 10:53 am
Hello everyone
Who can help me is what exactly is wrong in my script
my goal is to launch the command exec xp_readerrorlog 0,1
Import-Module sqlps -DisableNameChecking
$path='C:\localhost\serveur.txt'
$serveurs=Get-Content -path $path
$serveurs
$serveurs |foreach {
$query="exec xp_readerrorlog 0,1"
invoke-sqlcmd -Query $query -ServerInstance $serveurs
}
Here is the error
July 28, 2018 at 11:18 am
try
Import-Module sqlps -DisableNameChecking
$path='C:\localhost\serveur.txt'
$serveurs=Get-Content -path $path
$query="exec xp_readerrorlog 0,1"
foreach ($server in $serveurs)
{
invoke-sqlcmd -Query $query -ServerInstance $server
}
July 28, 2018 at 11:52 am
thanks
it works properly
another question please how can I add the name of my server in my script
I want to load the server name in front of each lineImport-Module sqlps -DisableNameChecking
$path='C:\localhost\serveur.txt'
[Array]$serveurs=Get-Content -path $path
$query="exec xp_readerrorlog 0 ,1"
foreach($server in $serveurs){
invoke-sqlcmd -Query $query -ServerInstance $server -Database master
}
July 28, 2018 at 4:43 pm
This really should not be sent to standard output but rather redirected to a database or a file as volumes can be quite high.
Import-Module sqlps -DisableNameChecking
$path='C:\localhost\serveur.txt'
[Array]$serveurs=Get-Content -path $path
$query="exec xp_readerrorlog 0 ,1"
foreach($server in $serveurs)
{
$results=invoke-sqlcmd -Query $query -ServerInstance $server -Database master
foreach($result in $results)
{
$result|Select-Object LogDate,ProcessInfo,Text|Select-Object -Property @{n="server";e={$server}},LogDate,ProcessInfo,Text
}
}
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply