|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Today @ 11:01 AM
Points: 4,
Visits: 72
|
|
| I changed the script to pull the server name from __Server instead of SystemName because a few of my servers had no information in that field. After doing that the column mapping gets skewed and columns from the data table are not matched up with the columns from the sql table durring the writetoserver call. Any idea's on how this column mapping can be set?
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Today @ 11:01 AM
Points: 4,
Visits: 72
|
|
I answered my own questions. You need to use:
$bulkCopy.ColumnMappings.Add("SourceCol", "DestCol")
to define the mapping between columns.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
You got it. Sometimes I'll just recreate the table definition to match the column order in order to avoid mappings.
If you go that route you'll need to look at the column order after its been converted to a datatable using get-member.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 8:42 AM
Points: 5,
Visits: 33
|
|
Hi, getting an error in the write-VolToDb
Exception calling "WriteToServer" with "1" argument(s): "Column 'server_name' does not allo w DBNull.Value." At C:\Bin\Write-VolToDb.ps1:89 char:28 + $bulkCopy.WriteToServer <<<< ($dt) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
Table is populated with one server, stepping through in debug mode (PowerGUI) is showing all parameters and connection strings are correct. Running a C:\Bin\test.ps1 connects and returns the correct server held in the server_space_iku.
Any ideas?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
Take a look at the $dt variable and make sure server_name property has a value.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 8:42 AM
Points: 5,
Visits: 33
|
|
| Yeah throughout the debugging, the @dt variable never appeared to have a value assigned. All other variables were populated, including server name etc
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 8:42 AM
Points: 5,
Visits: 33
|
|
I have narrowed it down. Removing the Primary Key from the table vol_space and allowing NULLS on the server_name field inserts records but without a server name. Somewhere the server\computer name is not being populated, maybe in the Out-DataTable funtion. The column names picked and added to the data table are:
FreeGb Label Name PercentFree SizeGB SystemName ? UsageDT
SystemName appears to be the culprit?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
Not sure why SystemName would be null. Let's try forcing the systemname. Replace the existing Get-Vol function with this version:
####################### function Get-Vol { param($computerName)
Get-WmiObject -computername "$ComputerName" Win32_Volume -filter "DriveType=3" | foreach { add-member -in $_ -membertype noteproperty UsageDT $((Get-Date).ToString("yyyy-MM-dd")) add-member -in $_ -membertype noteproperty SizeGB $([math]::round(($_.Capacity/1GB),2)) add-member -in $_ -membertype noteproperty FreeGB $([math]::round(($_.FreeSpace/1GB),2)) add-member -in $_ -membertype noteproperty PercentFree $([math]::round((([float]$_.FreeSpace/[float]$_.Capacity) * 100),2)) add-member -in $_ -MemberType noteproperty SystemName $ComputerName -force -PassThru } | select UsageDT, SystemName, Name, Label, SizeGB, FreeGB, PercentFree
}# Get-Vol
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 8:42 AM
Points: 5,
Visits: 33
|
|
Yes, that has fixed it. Thank you. 
I wonder why this happened.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 9:50 AM
Points: 4,
Visits: 121
|
|
Hi All,
In SQL Server 2008 instance i have created spacedm database and created all objects tables,views,sp's
I've executed this command prompt .\write-dbspacetodb.ps1 'instancename' spacedm
I am getting below error from powershell. An exception calling "fill" with "1" can't open database spacedm. Login failed to open Spacedm database
Please help me how to resolve this issue. I have created one login assigned db_owner to spacedm even then same issue.
|
|
|
|