header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
command from variable
Last Post 06 Sep 2011 11:54 AM by Bobdee. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
BobdeeUser is Offline
Basic Member
Basic Member
Posts:130
Avatar

--
06 Sep 2011 05:04 AM
    Hi,

    Is there anyway to build a command in a variable, then run it.

    I'm trying to do this by building a string from a sql query, then run it.  I thought I had done this before, but the more I think of it I'm not sure I have.

    I've tried creating an alias, but the command is not recognised.  Here is an example of what I am attempting (it's not actually what I want to do, but is a simple view of something similar)

    Thanks in advance.

    Invoke-Sqlcmd -ServerInstance db -Query "select 'get-qaduser ' + Userid as string from Users where userID like 'bbl12%'" | foreach {
    $string = $_.string
    # now I would like to run the command.
    }
    EBGreenUser is Offline
    Veteran Member
    Veteran Member
    Posts:1094
    Avatar

    --
    06 Sep 2011 06:33 AM
    I'm having a hard time understanding exactly what you need. You want to run a call to get-qaduser and use the result of that as part of your sql statement? If you could, please post an example of what you would like the resulting query string to look like.
    "Look Ma...no strings!"
    uSlackrUser is Offline
    New Member
    New Member
    Posts:68
    Avatar

    --
    06 Sep 2011 08:43 AM
    If I understand what you are asking - take a look at the Invoke-Expression command. it allows you to call code that is stored in a variable. This might help: http://blogs.msdn.com/b/powershell/...ssion.aspx

    \\uSlackr
    BobdeeUser is Offline
    Basic Member
    Basic Member
    Posts:130
    Avatar

    --
    06 Sep 2011 11:46 AM
    Perfect uSlacker - thanks for that.

    I had used it before, but completely forgot - so I appreciate you're help man.

    Bob
    BobdeeUser is Offline
    Basic Member
    Basic Member
    Posts:130
    Avatar

    --
    06 Sep 2011 11:54 AM
    EB - I wasn't trying to use the query that I put up, it was more an example.  Sorry if it was confusing, but thanks for posting - appreciate it.

    Bob
    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