top of page

PowerShell SQL One Off

6. I will also create a One Off Script to allow input from user to pull

a specific server 's data from SQL and export it. So one can get a

single server to review services. 

 

#Downloads and Installs SQL Module and Will Overwrite and Older Version Module Installed
Install-Module -Name SqlServer -AllowClobber
#Get Hostname from User
$MyComputer = Read-Host "Enter Computer Name"
#Query SQL for a Hosts Service Info by Server Name
$Invoke-Sqlcmd -ServerInstance Desktop-Main  -database ServerManager -Query "Select PSComputerName,Name,DisplayName  From ComputerServices Where PSComputername = '$MyComputer'" | Export-CSV "C:\temp\$Mycomputer.csv" -NoTypeInformation

SQL Insert from CSV File
bottom of page