TempDB move at include variable path

Welcome Forums General PowerShell Q&A TempDB move at include variable path

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 1 month ago.

  • Author
  • #92753

    Points: 0
    Rank: Member


    We have hundreds of Channel Database on multiple SQL server, usually we are facing the space issue. Now decided to move tempdb location from C to E drive with CDB path name (E:\Program Files\MMSSQLServer\MSSQL12.\MSSQL\Data\Tempdb.mdf)

    I am able to move the Tempdb with below script. BUT not able to set path passing variables in sqlquery:
    QueryPath= "C:\SQLCMD\SQLQuery.sql"
    $OutputFile = "C:\SQLCMD\QueryOutput.txt"
    $ExecuteQuery= Get-Content -path $QueryPath | out-string

    "Results — > `r`n`r`n" > $OutputFile

    $server = import-csv "C:\SQLCMD\ServerList.csv"
    $server | foreach-object {
    $ServerName = $_.serverName

    invoke-sqlcmd -ServerInstance $ServerName -query "$GO
    (NAME = tempdev, FILENAME = '$CDB')
    GO" -querytimeout 65534 | ft -autosize | out-string -width 4096 >> $OutputFile

    (NAME = tempdev, FILENAME = '$CDB')

    IT give me error as "invoke-sqlcmd : The path specified by E:\Program Files\MMSSQLServer\MSSQL12.\MSSQL\Data\Tempdb.mdf"
    $ServerName -query "USE master"

    I tried to pass variables using different method , but not work.

    Please help

  • #93121

    Points: 41
    Rank: Member

    Afraid I can't answer your specific query as to why this doesn't work for you and I don't have a SQL server to test against at the moment. However, you should take a look at dbatools.io.

    Specifically, you want the Set-DbaTembDbConfiguration cmdlet.

The topic ‘TempDB move at include variable path’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort