Refreshing the SQL Server PowerShell Provider

Sometimes SSMS gives you stale results and there you have the Refresh button to fix that.

In SQL PowerShell, the same situation can arise where the SQL Server PowerShell Provider is responding to your request with stale data. So how do you fix that? Pretty easily actually. Wherever you are just say Get-ChildItem “.” and wrap a “.Refresh()” method around it, like this:

(Get-ChildItem . ).Refresh()

(Get-ChildItem . ).Refresh()

If you want to refresh a different location than where you are in the provider right now, just replace the “.” with the path that you want refreshed.

(Get-ChildItem SQLSERVER:\SQL\LOCALHOST\SQL2016\Databases\AirStats\tables\).refresh()

The SQL PowerShell Provider for SSAS can suffer from the same situation (after all, so does working with SSAS in SSMS) but oddly, the fix is just slightly different. Different enough to drive you mad when you can’t find it! (Ask me how I know.)

(Get-Item SQLSERVER:\SQLAS\LOCALHOST\SQL2016\Databases\).Refresh()

You can also just refresh your current location like you can with the relational provider, just using this slightly different command:

(Get-Item . ).Refresh()

As I work on demos to raise awareness for things you can do and things that need added to SSAS+PowerShell, I ran into this and wanted to share it just in case I can save you the frustration of having to figure it out yourself.

That’s it for today! J

Please Share This:

You may also like:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Subcribe to Blog Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

What I'm Saying on Twitter

Subscribe via feedburner