Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Populate SQL Table with Powershell script Expand / Collapse
Author
Message
Posted Tuesday, January 15, 2013 3:30 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Saturday, September 6, 2014 2:15 PM
Points: 1,597, Visits: 1,153
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!
Post #1407131
Posted Tuesday, January 15, 2013 3:40 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Saturday, September 6, 2014 2:15 PM
Points: 1,597, Visits: 1,153
Just found this post which looks like it answers my questions :)

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


There's no kill switch on awesome!
Post #1407137
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse