Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
SQL Server
trouble with output format
Last Post 10 Oct 2009 07:15 AM by
dcoz
. 4 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
dcoz
New Member
Posts:16
07 Oct 2009 05:46 AM
Hi guys,
I am trying to create a simple script that produces the server names and last backup data for a particular SQL database.
what i have got to far is:
foreach ($sql in get-Content "servers.txt")
{ $srv = get-sqlserver $sql
$srvname = $srv.Name
$db = get-sqldatabase $srvname test
$dbprop = $db.Properties | Where-Object {$_.name -eq 'lastbackupdate'} |Select-Object value
}
I am trying to have the output show the server name and last backup date. At the moment just having trouble trying to see how i can get this output format.
Any help would be appreciated.
regards
DC
Chad Miller
Basic Member
Posts:160
07 Oct 2009 03:47 PM
$db | select @{name='Server';e={$db.parent.name}}, name, lastbackupdate
dcoz
New Member
Posts:16
08 Oct 2009 07:29 AM
Thanks cmille19 thats works great.
I'm wondering if you could explain what is going on in the line you gave me?
I understand some of it but just trying to get a better grasp of it.
thanks
DC
Chad Miller
Basic Member
Posts:160
08 Oct 2009 10:30 AM
Assigning a database object to the variable $db next we're using the select-object aka select to well, select specific properties of name and lastbackupdate. The Server name is not a property of database class natively, however in PowerShell there are several ways to add synthetic properties to an object. The way we are doing this in the code example above is by using an expression which is abbreviated "e"
The expression @{name='Server';e={$db.parent.name}} creates a new property callled Server, the value is assigned is $db.parent.name. The Parent property of a database object is a server object and the server class has a name property.
dcoz
New Member
Posts:16
10 Oct 2009 07:15 AM
I understand it alot better now thanks chad.
I appreciate the help.
Regards
DC
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
SQL Server
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2