SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Populate SQL Table with Powershell script


Populate SQL Table with Powershell script

Author
Message
Loundy
Loundy
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1826 Visits: 1190
Hi All,

I'd like to use a powershell script to populate a table with fixed drive space info.

here is the table schema:

IF OBJECT_ID(N'[dbo].[FixedDriveInformation]', N'U') IS NULL
BEGIN

CREATE TABLE dbo.FixedDriveInformation
(
Id INT IDENTITY(1,1) NOT NULL
,ServerInstance VARCHAR(100) NOT NULL
,DriveLetter CHAR(1) NOT NULL
,DriveLabel VARCHAR(50) NOT NULL
,GBFreeSpace NUMERIC(2,2) NOT NULL
,DriveSize NUMERIC(2,2) NOT NULL
CONSTRAINT [FixedDriveInformation_Id] PRIMARY KEY CLUSTERED (Id)
)

IF OBJECT_ID(N'[dbo].[FixedDriveInformation]', N'U') IS NOT NULL
BEGIN

PRINT 'SUCCESS - Table [dbo].[FixedDriveInformation] created.'

END
ELSE
BEGIN

RAISERROR('FAIL - Table [dbo].[FixedDriveInformation] not created.',16,1)

END

END
ELSE
BEGIN

PRINT 'EXISTS - Table [dbo].[FixedDriveInformation] already exists.'

END

GO



Here is the powershell code i'm using:

gwmi win32_volume -filter 'drivetype = 3' | select driveletter, label, @{LABEL='GBfreespace';EXPRESSION={"{0:N2}" -f ($_.freespace/1GB)} }, @{LABEL='DriveSize';EXPRESSION={"{0:N2}" -f ($_.Capacity/1GB)}}

Does anyone know the best way for me to go about doing this?

Cheers,

There's no kill switch on awesome!
Loundy
Loundy
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1826 Visits: 1190
Just found this post which looks like it answers my questions Smile

http://www.sqlservercentral.com/articles/powershell/65196/

There's no kill switch on awesome!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search