header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
trouble with output format
Last Post 10 Oct 2009 07:15 AM by dcoz. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
dcozUser is Offline
New Member
New Member
Posts:16
Avatar

--
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 MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    07 Oct 2009 03:47 PM
    $db | select @{name='Server';e={$db.parent.name}}, name, lastbackupdate
    dcozUser is Offline
    New Member
    New Member
    Posts:16
    Avatar

    --
    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 MillerUser is Offline
    Basic Member
    Basic Member
    Posts:160
    Avatar

    --
    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.
    dcozUser is Offline
    New Member
    New Member
    Posts:16
    Avatar

    --
    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.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer