Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Browsing latest articles
Browse All 467 View Live

Could not load file or assembly Microsoft.SqlServer.Smo, Version=9.0.242.0

Hi allA lot happened on my machine at work last week - I installed Visual Studio 2015 which somehow messed up my SQL 2016 install. So I uninstalled SQL 2016 (and too the opportunity to clear out other...

View Article


replace the result of a list with the result of a select query

Hello everyoneI need to replace a predefined list by the result of a select querymy list is statistically defined [code language="sql"]$path=@("\\Filer1\sql-bck$","\\filer2\sql-bc

View Article


Write PowerShell Output to SQL Server Table

Heh... First time I've had to admit being a "newbie" in a long time so be gentle with me. I might not even know enough to ask the right questions. I managed to pick up the following PS script from the...

View Article

Email

I have this piece of code which is currently working but I  an additional column added to the existing table and then emailed.$Header = @"TABLE {border-width: 1px; border-style: solid; border-color: b

View Article

Powershell email throwing error

$File="gci \\abcd\efgh\ijkl | select -last 1"$From = "adcb@gmail.com"$To = "efgh@gmail.com"$Attachment = $File$Subject = "Here's the Email Subject"$Body = "This is what I want to say"$SMTPServer =...

View Article


How Do You Connect to a Central Management Server If Your Server is a Named...

I have the following code that worked on a default instance.  Now I am trying to get it to work on a named instance.  I have tried replacing the \ with %5C.  That didn't work.  Any help would be...

View Article

Task scheduler powershell code not sending email to multiple recipients

.

View Article

restore all databases

Hello everyoneI need to restore almost 100 backup put on a folder through a single scriptfor that I try to script these 3 lines but the powershell it makes me return errors that can correct me 

View Article


Powershell Tranasctions

I have a Powershell script that gets a list of files from a SQL PROC.For each file, it then moves a file, then updates a DB record, then inserts a DB record.How can I encapsulate the whole process (IO...

View Article


Extract data into a HTML table from multiple sql servers using powershell

$Header = @"<style>TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black;...

View Article

do not display empty folders on the report

$Header = @"<style>TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black;...

View Article

Programmatically trigger an event on a WinForms object in Powershell

Hi all,Let's say I've got a label ($ObjLabel) and a checkbox ($ObjCheckBox), that is created not checked, and added to my form.I've got code in the CheckedChanged event that changes the text in the...

View Article

Move files without moving subfolder files

I have been tasked with building a powershell file mover to move files (which could have any name and possibly no extensions) from one share to another. My problem is the source share has a subfolder...

View Article


Deploy Dacpac on remote machine using Powershell

Hi, I am on machine A with windows credentials say UserA and corresponding windows password. I will run powershell script on this machine. SQL 2016 DB is to be deployed on another machine say B. but...

View Article

Need Powershell command to list # CORES per computer -- qualified by Computer...

We need to list #CORES per SQL Server Computer in our environment.  (we have over 200 SQL Servers).  This Powershell command works great for 1 computer:Get-CimInstance -ClassName 'Win32_Processor' |...

View Article


Dbatools Credential issue ?

I am trying to use the Dbatools powershell module, but when I try to pass an AD credential, it is not seeming to work for me. I tried using both Invoke-Sqlcmd2 and Invoke-DbaSqlquery. I am passing a...

View Article

Is this way of writing code flexible enough for many administrative tasks?

I know there are multiple ways to skin the powershell cat and am currently settled on this solution.In this example, I use 'Microsoft.SQLServer.Management.SMO.Server' to retrieve data (rather than a...

View Article


date formats

((Get-Date).AddMonths(1)) gives meSaturday, August 25, 2018 3:06:26 AM(Get-Date -format 'Y')gives me July, 2018How do  i get August, 2018 when I run code  in the month of July with the output in this form

View Article

Execute Powershell script from SSIS using UNC Path

I'm trying to execute a Powershell script that sits on a network file share using SSIS Execute process task. When I run the package locally, it works fine, but when I run it on my server using SQL...

View Article

Error Powershell

Hello everyoneWho can help me is what exactly is wrong in my scriptmy goal is to launch the command [code language="sql"]exec xp_readerrorlog 0,1[/code][code

View Article

Convert VbScript Com object to PS to load sql2005 DTS pkg

Trying to Convert VBScript Com Object to PS. VbScript:Set objPkg = CreateObject("DTS.Package") objPkg.LoadFromSQLServer machine,,,DTSSQLStgFlag_UseTrustedConnection,,,,packageName...

View Article


get-childitem in multi path

Hello everyonehow to run the get-childitem command on multiple pathIn fact I have more path and I want to apply get-childiteam on these pathI have in my code $path,$path1,$path2[code langua

View Article


Problems with getting my hash table populated

HelloI'm trying to  to insert values of sql server script into my hash table to be used later on another process, the piece that I'm using is:$instancename ="instancename"$databasename...

View Article

insert the errorlog in sql table

Hello everyoneI am looking for a method to insert the contents of this script into a sql server table[code language="sql"]Import-Module sqlps -DisableNameChecking$serveurs=@("localhost\sqlprod","loca

View Article

use Powershell scripts on a Non-sql server

I inherited Powershell scripts that run on a non SQLServer box A and invokes invoke .net commands to connect to SQLserver databases on another box and return datasets. I have the task to install a new...

View Article


Using Powershell and code encryption. New to this stuff

Below is a powershell script. Looks like it is encrypted with a signature block. I want to make a small change to server name in the script. After the change i have to encrypt the ps1 file again with a...

View Article

parse string and check for valid date

I have a flat file with a bar(|) delimiter. It has no headers, but I want to check columns(11,12,13) for valid dates. If invalid date found in any of the fields display entire record andfail the...

View Article

Image may be NSFW.
Clik here to view.

invoke-sqlcmd timeout

Hi everybodyWho can help me on invoke-sqlcmd-level timestamp i tried it with invoke-sqlcmd2 but I still have pb

View Article

How to output everything to a log file in Invoke-SqlCmd

I have powershell script to run database scripts below, but I can't get it to output to my logfile the "..x row(s) affected"(the messages that you see in SSMS) output whether I run an update, delete,...

View Article



List all ADGroups and all their Users

ForEach ($Group in (Get-Content c:\text.txt)) { Get-ADGroupMember $Group | Select @{Label="Group";Expression={$Group.Name}},Name,SamAccountName }I have the above piece of powershell code which displays...

View Article

SQL Agent job not failing when Powershell script errors

First time using Powershell. And I'm trying to execute via SQL Agent job. So I don't know if I have something wrong in my Powershell script or my SQL Agent job or Both. SQL Server 2008 R2 PowerShell...

View Article

Application Intent with Invoke-SQLcmd

Are you able to specify read-only routing in invoke-SQLcmd? $dataTable = Invoke-Sqlcmd -Query $Query -Database $SourceDatabaseName -ServerInstance $SourceServerName ; maybe add something like -READONLY...

View Article

Services

I need to go through a list of SQL Servers from a SQL table;hit the respective server and collect this data (SystemName, DisplayName, Name, State, Status, StartMode, StartName) and insert those values...

View Article


WMI connection error using Invoke-Sqlcmd

Hi all,I'm brand new to powershell and am trying to convert an old batch script that run some sql files via sqlcmd command to a powershell script.This is my test script so far:[code la

View Article

Run New PowerShell Process As A Different User

Hello,I'm trying to create a PowerShell script that will run a new PowerShell Process as a different 'Windows' user.  The following code seems to work for running the new process as the different user,...

View Article

List edition and version of all SQL Server machines over the Network ...

In our organization, we have more than 100 SQL Server machines on different regions over the Network/LAN/WAN. We have restricted the network to do not go out of subnet/your allowed access until...

View Article


Help with List Variable

Hi, Please could anyone help me with following requirement. I have output like below -

View Article


Get Max Number of error log files

Creating Audit script to validate newly built sql server- as it's popular now- in PS. Do not have much experience with PS- learning on the fly- moving slowly but steadily. Stuck with validating Max N...

View Article

skip function if completed successfully

I have a function where I'm executing in succession a list of sql queries\updates. The function has try\catch so if it detects error. My questionis( hopefully asking correctly) is there a way if one...

View Article

change the credentials for SQL Server Agent on all the nodes of a cluster

I'm running into a problem on a simple powershell script to change the credentials for SQL Server Agent on all the nodes of a cluster. Something is going wrong when I pass values to the...

View Article
Browsing latest articles
Browse All 467 View Live