Stuck in Powershell sqlserver

From MS article SQL Server PowerShell

•A SQL Server provider, which enables a simple navigation mechanism similar to file system paths. You can build paths similar to file system paths, where the drive is associated with a SQL Server management object model, and the nodes are based on the object model classes. You can then use familiar commands such as cd and dir to navigate the paths similar to the way you navigate folders in a command prompt window. You can use other commands, such as ren or del, to perform actions on the nodes in the path.

Having a provider like this loaded allows you to treat the SQLServer the same way you would treat a drive (letter).

So most likely somewhere in your code you've used CD to move into the SQLServer provider (cd sqlserver:).

If you wanted to get back to d:\thefolder specifically you'd use cd d:\thefolder.

If you want to return to where you started when done, then you'll probably have to store the current directory location into a variable a the start of the script, and then use it with cd at the end of the script to change back to that original directory.

Or you could, as suggested by @alroc's in his comment, use the push-location and pop-location cmdlets to store and retrieve the current location.


this seems to works for me:

Invoke-Sqlcmd -InputFile "C:\MyFolder\TestSqlCmd.sql" | out-null

Tags:

Powershell