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 internet. Lot's of you know what it is. It gets some disk space information from every disk device for the given computer. I've removed all field formatting just to keep it super simple.[code="plain"]Get-WmiObject Win32_LogicalDisk -computer 'SomeComputerName' | Select SystemName,DeviceID,VolumeName,Size,FreeSpace | Format-Table[/code]What I'd like to do is write the output to a table in a given SQL Server. I've Googled for answers and have found some (IMHO) very over complicated methods. Some are generic (which is very cool) but not what I need. I just want to write this one output to a table.The table for this example is simple as well (I've removed all but the necessary columns including a Date/Time column)...[code="sql"] CREATE TABLE dbo.DiskSpace ( SystemName VARCHAR(128), DeviceID CHAR(2), VolumeName VARCHAR(128), Size BIGINT, FreeSpace BIGINT );[/code]I realize that we're going to need a connection to the database. I'd like it to be a trusted connection so we don't have to hardcode a user name or password. Assume that the server name is "TestServer" and that the database name is "TestDB". From what I've been able to read up on, the business of the connection would look something like this (please correct it if I'm wrong)...[code="plain"]$conn=new-object System.Data.SqlClient.SQLConnection $ConnectionString = "Server=TestServer;Database=TestDB;Integrated Security=True;Connect Timeout=0"$conn.ConnectionString=$ConnectionString $conn.Open()...something goes here but I don't know what... $conn.Close() [/code]Like I said, I'm brand-spanking-new to PowerShell. I sure could use some help on how to get the data from the first script above into the table that I posted the CREATE TABLE code for without having to build a bunch of functions like in the following link.[url]http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx[/url]Thanks for the help, folks. And, yeah... if you have a good book recommendation for the syntax and how to "start thinking in PowerShell" like I do in T-SQL, it would also be much appreciated.
↧