Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Request a Script

Thread: Converting table value to string/variable

This question is answered. Helpful answers available: 2. Answered answers available: 1.


Permlink Replies: 6 - Pages: 1 - Last Post: Nov 26, 2009 4:51 AM by: Colan
Colan

Posts: 5
Registered: 11/24/09
Converting table value to string/variable
Posted: Nov 24, 2009 8:01 AM
 
  Click to reply to this thread Reply

Hai Experts,

I'm using Powershell to automate a bunch of thing, such as DPM

I'm deploying backups to an external disk and want it to automatically change the foldername in which it unpacks to that of the machine the backup came from

now I can get a table with only one line, which contains the computername, diskname and type of the machine and location which was the original for the backup

the table looks something like this:
Computername---Name---Type
servername---------C:\------Volume

but I can't seen to be able to select the value's in the table anyhow,

and now I want to be able to convert the servername into $servername and the Name into $diskname

anyone have any ideas?



seaJhawk


Posts: 414
Registered: 12/15/08
Re: Converting table value to string/variable
Posted: Nov 24, 2009 8:20 AM   in response to: Colan
 
  Click to reply to this thread Reply

Hi Colan,
How are you getting the table?

/chris


Colan

Posts: 5
Registered: 11/24/09
Re: Converting table value to string/variable
Posted: Nov 24, 2009 8:34 AM   in response to: Colan
 
  Click to reply to this thread Reply

I'm getting it through running the following script, mind you: it's mostly DPM cmdlets

$pg = Get-ProtectionGroup evi-dpm-01
$ds = Get-Datasource -DpmServerName evi-dpm-01
$rp = Get-RecoveryPoint -Datasource $ds[$number] |Measure-Latest
$ri = Get-RecoverableItem $rp -browsetype child

$ds[$number] would be my used to obtain the list here
$ds is a list of all backed-up computers, and with he $number I select the one I want to recover

Measure Latest is one of Dmitri's solutions: http://dmitrysotnikov.wordpress.com/2008/07/16/measure-latest-finding-the-latest-date-time/



seaJhawk


Posts: 414
Registered: 12/15/08
Re: Converting table value to string/variable
Posted: Nov 24, 2009 8:43 AM   in response to: Colan
 
  Click to reply to this thread Reply

Can you provide an example of what you get if you type $ds[$number] at the command line?  I need to see what the raw output looks like.

-Chris


Colan

Posts: 5
Registered: 11/24/09
Re: Converting table value to string/variable
Posted: Nov 25, 2009 12:43 AM   in response to: Colan
 
  Click to reply to this thread Reply

here you go ('m doing through the normal DPM management shell, I haven't figured out how to run the DPM cmdlets in Powergui)

(next post for pic, this went wrong, attaching images in edit mode isn't available)
Message was edited by: Colan


Colan

Posts: 5
Registered: 11/24/09
Re: Converting table value to string/variable
Posted: Nov 25, 2009 12:46 AM   in response to: Colan
 
  Click to reply to this thread Reply

(image)



Colan

Posts: 5
Registered: 11/24/09
Re: Converting table value to string/variable
Posted: Nov 26, 2009 4:51 AM   in response to: Colan
 
  Click to reply to this thread Reply

I've managed to fix it,

this is the solution to my problem:

[string]$dsname = $ds[$number]
$computername= $dsname.Substring(16)
$diskname= $dsname.Substring(0,1)
$bfremote = "M:\backup\$computername\$diskname"
$bflocal = "H:\backup\$computername\$diskname"
New-Item $bfremote -type directory -force


here's the complete code in case anyone is curious as to how the entire mechanism works:
Add-PSSnapin "Microsoft.DataProtectionManager.PowerShell"

function Measure-Latest {
    BEGIN { $latest = $null }
    PROCESS {
            if (($_ -ne $null) -and (($latest -eq $null) -or ($_ -gt $latest))) {
                $latest = $_
            }
    }
    END { $latest }
}

$number = read-host "Bronkeuze"
$dpmserver = gc env:computername
$pg = Get-ProtectionGroup $dpmserver
$ds = Get-Datasource -DpmServerName $dpmserver

[string]$dsname = $ds[$number]
$computername= $dsname.Substring(16)
$diskname= $dsname.Substring(0,1)
$bfremote = "M:\backup\$computername\$diskname"
$bflocal = "H:\backup\$computername\$diskname"
New-Item $bfremote -type directory -force

$rp = Get-RecoveryPoint -Datasource $ds[$number] |Measure-Latest
$ri = Get-RecoverableItem $rp -browsetype child
$ro = New-RecoveryOption -TargetServer server.company.local -RecoveryLocation copytofolder -FileSystem -AlternateLocation $bflocal -OverwriteType overwrite -RestoreSecurity -RecoveryType Restore
$job = Recover-RecoverableItem -RecoverableItem $ri -RecoveryOption $ro

while (!$job.HasCompleted)
{
    $time = Get-Date –f "HH:mm:ss"
    Write-Host "$time - Job status: $($job.Status)"
    sleep 60
}
Write-Host "Job has completed. Final status: $($job.Status)"



Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums