Hi,
I am trying to get performance data using powershell. When I run the command "get-wmiobject -list" I get classes like
Win32_PerfRawData_MSSQLSQLEXPRESS1_MSSQLSQLEXPRESS1Locks. However when I run the command
get-wmiobject -query "select * from Win32_PerfRawData_MSSQLSQLEXPRESS1_MSSQLSQLEXPRESS1Locks" powershell gives me an error. Why is this happening? any help in this regard is appreciated.
We are in plan to build a Monitoring tool using PowerShell and Performance Monitor which could monitor 10 to 20 servers. Do you have any reference of any existing tool using Performance Monitor to monitor the SQL Server and available for free? I didn't want to put some effort, if something is available already.
I am searching for a Powershell script which picks Windows Server names from SQL server table(eg: Instance.DB.tbServerList) & writes last reboot date to SQL server table(can be same or different table).
I would like to use powershell commands within my TSQL scripts. how to do that?
The reason is that up until now I have been using SQLCMD and XP_CMDSHELL to rename files before importing them into a database. Powershell is a better tool for this job.
I have a new problem with doing a restore of a number of databases using powershell. The script I'm using is based mainly on this one (Part 2 in particular): [URL] .....
The problem I'm having is around the RedgateGetDatabaseName function. My hunch is that its down to the different version of red gate and how sqlbackup works. Basically when the call is made to the function it is returning both the Database Name and the number of row's that the SQL command in the function has ran. I've tried to include a SET NOCOUNT ON at the start of the SQL command in the function but its still returning the now count.
When I execute the following command, I get the output truncated to 79 characters, including three dots (as an ellipsis, I suppose).
EXEC master..xp_cmdshell 'powershell.exe "Get-ChildItem D:Databazepaleontologieprilohyverejneg -filter g417*.* -recurse | select Fullname | out-string -width 255"'When I execute the core command directly in Powershell, whether the text or ISE version, it works correctly, with or without the out-string -width command.
Get-ChildItem D:Databazepaleontologieprilohyverejneg -filter g417*.* -recurse | select Fullname | out-string -width 255What does it take to get SSMS to not truncate my output strings?
I have a SQL Server 2014 instance running on a SQL Server 2008 R2 server. The server is not clustered, it is just a stand alone SQL Server. The syspolicy_ purge_history job fails every now and then with the error message: "A job step received an error at line 1 in a PowerShell script. The corresponding line is 'import-module SQLPS -DisableNameChecking'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Access to the path 'PowerShell_CommandAnalysis_Lock' is denied. '. Process Exit Code -1. The step failed."
Google isn't bringing up much besides the whole"If this is a clustered server make sure you have the right server name in the command" answer, which isn't the case here. Some days this job fails and some days it succeeds. I have checked out task scheduler to see if there were any conflicts there, found nothing. Nothing in the event viewer either.
I'm trying to create a restore job for restore job in sql using PowerShell but I get the following error:
The job script encountered the following errors. These errors did not stop the script:
A job step received an error at line 1 in a PowerShell script. The corresponding line is 'Set-location "filelocation"'.
Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot find path 'filelocation' because it does not exist.
' A job step received an error at line 3 in a PowerShell script. The corresponding line is 'get-childitem -Filter '*.trn' | Select FullName, LastWriteTime | sort LastWriteTime -Descending | ft -AutoSize'.
Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot call method. The provider does not support the use of filters. '. Process Exit Code -1. The step failed.
I am trying to create a job using power-shell script to move the backup files from one folder to another. I am using Ola Hallengren script for backups. Ola hallengren created a common backup folder with sub-folders for databases and even more sub folders for Full and Log backups. My goal is to move full backups, which are older than a month and save them in a different drive along with the same folder structure. I was able to move the first set of backups without any problem, but I can't move anymore files and keep getting this error even when I try to overwrite the previous file with the force statement:
Move-Item : Cannot create a file when that file already exists.
I want to run a powershell script using xp_cmdshell, put the results into a temp table and do some additional stuff.I'm using:
CREATE TABLE #DrvLetter ( iid int identity(1,1) primary key ,Laufwerk char(500), ) INSERT INTO #DrvLetter EXEC xp_cmdshell 'powershell.exe -noprofile -command "gwmi -Class win32_volume | ft capacity, freespace, caption -a"' select * from #DrvLetter SQL server is cutting off the output, what I get is (consider the 3 dots at the end of a line):
i am using powershell to get the output..I am planning implement sorting to my output.below is the format I am writing my objects to html file.I want sort the object of lastrunoutocome field.
I would get from scripting the replication out from SQL Server itself. However, there are a couple of things that are not showing up in the script,Adding the option to IncludeUninstallDistributor or UninstallDistributor doesn't appear to add any code to actually do that. i.e. the below code is never added.
/****** Uninstalling the server as a Distributor. Script Date: 10/1/2015 4:34:13 PM ******/ use master exec sp_dropdistributor @no_checks = 1, @ignore_distributor = 1 GO Also, adding the reverse for the create script generation, IncludeInstallDistributor or InstallDistributor, does not add the below code. use master exec sp_adddistributor @distributor = N'xxxxxx', @password = N'' GO
The purpose of the script is simply to script out all drop/create scripts for all publications and subscriptions, run the drop script, restore over the databases using backups of non-replicated databases, run the create replication script, and have it re-sync.
1) I can connect to SQL Server 2012 named instance from SSMS.
I can launch Power shell in any of the supported data contexts, for example from the named instance.
However when I try to run a query in Power Shell, I get the named pipes error.
2)I can also provide a connection string and connect to the SQL Server Instance form Windows PowerShell after launching SQLPS, the same as in the above. I can open the connection and verify its state, but trying to run a query results in the same error.
I also see that named pipes is enabled in the SQL Server Configuration Manager.
Some of this is the result of some ambiguity in the Windows User Account in Windows 8 computer. Some of this is documented in more detail here: [URL] .....
This link is not directly related to the above problem, but arises out of the ambiguity in the Username retrieval: [URL] ....
As a part of DBA, I used to execute various SQL files. Most of the time, it is like a manual effort to execute the files individually.
I am looking to automate the process, like a single click to execute all the .SQL files.
The main hurdle I have is, some files needs to be executed in A1 database, some in B1 database and some other SQL files need to be executed in C1 database. In this scenario, I need to pass the DBName information to the powershell query dynamically.
My design for this requirement is, say each .SQL file need to contain a template like
@DBName = 'your Database name' @Executeon = 'When to execute'
In this case, the powershell first need to read the SQL file and finds the value for @DBName and replace it in the powershell query and execute the SQL files automatically.
Is it feasible ? Or any other alternate easier way to proceed.
I have a job which copies .txt files 24 hours 7 days a week to c:TempSource
What I am planning to do is copy the files from one location to another say c:TempTarget
So I have written the Powell shell script and when i put that in the sql agent job i get below error ;
A job step received an error at line 5 in a PowerShell script. The corresponding line is '$filesToMove = $files | Where -Property "Name" -NotLike -Value $newestFile.Name'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'A parameter cannot be found that matches parameter name 'Property'. '. Process Exit Code -1. The step failed.
As we know there are two output windows in sql server management studio like 'Results' and 'Messages', I want to capture that 'Messages' window into a log file using powershell program . like into a log file it should display like :
I am trying to update my SQL table using an update query in powershell from an excel sheet.
The query is as follows,
#building name from excelsheet $TCell=$reader.GetValue(8); #update query is as, $CreateScript1= "UPDATE $DestinationTable SET $DestinationTable.Phone = '$SCell' WHERE RoomNumber = '$FCell' and buildingname like ''$TCell'%'"
I want to use like operator in the query to compare building name from excel sheet with the building name in sql table. I am facing an error in the highlighted part. I am not sure if my query is right or wrong.
I am trying to automate the setup of SQL server 2014 Standard edition with SSRS. To avoid SSRS being setup using the default port 80 for the webservice and report manager url's, I've chosen to install SQL server with the setting RSINSTALLMODE="FilesOnlyMode" and then use powershell to do the final setup steps.To setup the ReportServer database, I use the "GenerateDatabaseCreationScript" method available in the "MSReportServer_ Configuration Setting" class.
This succeeds without problems however when I use my browser to connect to the web service or report manager url's, I get a "rsInvalid Report Server Database" and a "rsReportServerDatabaseUnavailable " error, respectively.Running the stored procedure named GetDbVersion in the ReportServer database returns "C.0.9.45". If I delete the ReportServer database and then recreate it database manually with the Report Services Configuration manager, the same stored procedure returns "162".
So it seems to me there's a problem with the GenerateDatabaseCreationScript but I can't find any information on this. How can I automate the setup of SSRS and ensure it does not use port 80? There are many manual solutions involving multi-step GUI solutions but the key for me is to automate this with powershell which doesn't appear to be possible.
I am looking for a sample PowerShell script that allows me to verify that showplan is enabled for a user on a SQL Server 2012 instance. Haven't figured out how to code it.
We have 15-20 report server environments including Dev/SIT/UAT/PROD/DR etc. so instead of configuring it on each servers, we would like a script to use with parameters.
After installing the SSRS 2012 package on each server with given instance and service account, I would like to configure the SSRS through script instead on running the Configuration manager RSConfigTool.exe manually.
we already have created the database beforehand using the scripts provided by WMI. do we need db_owner permission on msdb and master database to configure SSRS?
In case of command execution from project PowerShell SSIS, writes only Failure to what there can be a problem? From VS it is launched without problems.
We have been looking for a way to executing bursting of SSRS reports within SharePoint (integration mode) from a SSIS package after a successful load. We found this MSDN article which has a PowerShell script to "fire" a subscription.URL....One of the parameter needed is the SubscriptionID.
I am using SSIS 2012 to dynamically backup stored procedures on a list of Servers and Databases.Here are the steps in my package,
1. Execute SQL Task: Captures a result set (configured to save the data set in an Object variable) with all the Servers and Databases on which stored procedures exist.
2. For each loop that is configured to get each each row(server name @[User::Server_Name] and databases name @[User::DataBase_Name]) from the object variable (@[User::Connection_Strings])and pass it to a connection manager that has an expression for servername and database name.
2a) Within the for each loop, i have an execute process task that is configured as
i) Executable: C:WindowsSystem32WindowsPowerShellv1.0powershell.exe ii) Arguments: Configured this to fetch value from an expression. The expression i am using is,'C:batch - CopyPowerShell Scripts to Backup Stored ProceduresScriptOutSPs.ps1' -$Server_Name "+ @[User::Server_Name]+ " -$Database_Name "+ @[User::DataBase_Name]
Note: @[User::Server_Name] is the Servername from object variable and so is @[User::DataBase_Name] for database name . The execute task is to run a command line that triggers a powershell script with parameters. Here is the powershell script that i am using,
When i execute the script, by passing parameters from arguments, it executes successfully but nothing happens. Passing wrong arguments in the expression?
I am trying to delete tables from data where the ModifiedDates older than 9 years in AdventureWorks2012 database . I get console notified that foreign keys are dropped but the delete statement is throwing errors. I am sure that somewhere the key constraints are not getting altered, but i'm not able to figure it out as i'm a relative beginner to T-SQL. The error and code:
The DELETE statement conflicted with the REFERENCE constraint "FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID". The conflict occurred in database "AdventureWorks2012", table "Sales.SalesOrderHeader [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null $option_drop = new-object Microsoft.SqlServer.Management.Smo.ScriptingOptions; $option_drop.ScriptDrops = $true;