是否有PowerShell函数可在重新启动后重新连接到SQL Server?

j0pj023g  于 2022-12-10  发布在  Shell
关注(0)|答案(1)|浏览(99)

I have a basic Microsoft SQL Server (SQL Server 2017 on Server 2016 Datacenter) in Azure that's currently being power-managed. Every morning I RDP into the VM, enter the SQL Server Management Studio, and reconnect using my local admin account.
The machines automatically reboot, but is there a way to automate the reconnection process?
I reconnect using a GUI interface with the fields:

  • Server Type: Database Engine
  • Server Name: hostname
  • Authentication: Windows Authentication User name: localadmin Password:

I then click connect and boom. It seems like there should be a function, something like:

Reconnect-SQLServer -Type DatabaseEngine -Name hostname 
         -Authentication Windows -Credentials $Credentials

Is there? I haven't been able to find one. Bear with me, I'm fairly new to this sort of stuff.
Edit: It was my impatience. After a short period of time, the database was online and automatically reconnected. The manual process was not needed. Thanks to those who tried to help out.

tpgth1q7

tpgth1q71#

You can automate connecting sql server management studio with SSMS.exe flags like:

# use current running credentials for windows authentication
SSMS.exe -E -S hostname -d MyDatabase -nosplash

# use specific user account (will prompt for password)
SSMS.exe -U MyUserName -S hostname -d MyDatabase

It kind of sounds like you need something to just end the power-management? It would depend on how that is configured
I'm not familiar with Citrix, but it looks like there is a powershell module for monitoring/managing it and its database connections with cmdlets like Get-BrokerServerStatus for example:
https://support.citrix.com/article/CTX232979/how-to-connect-site-to-sql-ha-sql-mirror-or-a-new-sql-server-after-migrating-your-database

相关问题