Fairly new to powershell, but not to programming.I've got the script below, that i [b]thought[/b] was going to create a array that i could lop through.when i write out the contents, i'm getting the # of elements as an initial value, like below:[quote][color="#0000FF"]VERBOSE: Database Name: 3VERBOSE: Database Name: CommonSecurityVERBOSE: Database Name: dbWardenVERBOSE: Database Name: ReportServerTempDB[/color][/quote]would someone be kind enough to offer an example or point out what i'm doing wrong?[code]#################################################################################################### All servers In SIMPLE Recovery, thus needing FULL/DIFF strategy.###################################################################################################function Get-DbListSimpleRecovery($svr) { $SqlQuery = "select [name] from master.sys.databases where recovery_model_desc = 'SIMPLE' and database_id > 4 order by [name]" $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True" $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.CommandText = $SqlQuery $SqlCmd.Connection = $SqlConnection $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlAdapter.SelectCommand = $SqlCmd $DataSet = New-Object System.Data.DataSet $SqlAdapter.Fill($DataSet) $SqlConnection.Close() $results = @() foreach ($Row in $DataSet.Tables[0].Rows) { $results += $Row.name; } return $results}#$WhichServer = "LOWELL-DEV"#if blank, uses the default intance of the lcoal server $dbs = Get-DbListSimpleRecovery($WhichServer) foreach($db in $dbs) { write-verbose -Message "Database Name: $db" -verbose }[/code]
↧