![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | $Variables I have been trying to use a $variable to control my format-table command. --------------------------------------------------------------------------------------------------------- $Item = "DeviceId, MediaType, Size, FreeSpace" get-wmiobject -query "Select $Item from win32_logicaldisk" ` |sort mediatype | format-table $Item -auto -groupby MediaType # |sort mediatype | format-table $ExecutionContext.InvokeCommand.ExpandString($Item) -auto -groupby MediaType -------------------------------------------------------------------------------------------------------------- As you can see from the remmed out line I have been trying a variety of techniques. While I have learnt a lot about , $ExecutionContext.InvokeCommand.ExpandString and defining variables with [string] and other [types], I have not solved my problem. Here is a version that does work perfectly well, but I love employing variables. -------------------------------------------------------------------------------------------------------------- get-wmiobject -query "select DeviceId, Status, MediaType, Size, FreeSpace from win32_logicaldisk"` |sort | format-table DeviceId, MediaType, Size, FreeSpace -groupby MediaType -auto Can you help get it working with a $Item variable? Guy |
| | #2 (permalink) |
| Guest | Re: $Variables On May 31, 9:02 am, "Guy Thomas" <g...@computerperformance.co.uk> wrote: > I have been trying to use a $variable to control my format-table command. > > ---------------------------------------------------------------------------*------------------------------ > > $Item = "DeviceId, MediaType, Size, FreeSpace" > > get-wmiobject -query "Select $Item from win32_logicaldisk" ` > > |sort mediatype | format-table $Item -auto -groupby MediaType > > # |sort mediatype | format-table > $ExecutionContext.InvokeCommand.ExpandString($Item) -auto -groupby MediaType > > ---------------------------------------------------------------------------*----------------------------------- > > As you can see from the remmed out line I have been trying a variety of > techniques. While I have learnt a lot about , > $ExecutionContext.InvokeCommand.ExpandString and defining variables with > [string] and other [types], I have not solved my problem. > > Here is a version that does work perfectly well, but I love employing > variables. > > ---------------------------------------------------------------------------*----------------------------------- > > get-wmiobject -query "select DeviceId, Status, MediaType, Size, FreeSpace > from win32_logicaldisk"` > > |sort | format-table DeviceId, MediaType, Size, FreeSpace -groupby > MediaType -auto > > Can you help get it working with a $Item variable? > > Guy You should make your variable an array, because that is what is passed to format-table when you use the literal syntax, e.g.: $item = @("DeviceId", "MediaType", "Size", "FreeSpace") get-wmiobject -query "Select $Item from win32_logicaldisk" ` | sort mediatype | format-table $Item -auto -groupby MediaType Hope this helps, - Oisin |
| | #3 (permalink) |
| Guest | Re: $Variables "Oisin Grehan" <oising@gmail.com> wrote in message news:1180619962.555154.39380@q69g2000hsb.googlegroups.com... On May 31, 9:02 am, "Guy Thomas" <g...@computerperformance.co.uk> wrote: > I have been trying to use a $variable to control my format-table command. > > ---------------------------------------------------------------------------*------------------------------ > > $Item = "DeviceId, MediaType, Size, FreeSpace" > > get-wmiobject -query "Select $Item from win32_logicaldisk" ` > > |sort mediatype | format-table $Item -auto -groupby MediaType > > # |sort mediatype | format-table > $ExecutionContext.InvokeCommand.ExpandString($Item) -auto -groupby > MediaType > > ---------------------------------------------------------------------------*----------------------------------- > > As you can see from the remmed out line I have been trying a variety of > techniques. While I have learnt a lot about , > $ExecutionContext.InvokeCommand.ExpandString and defining variables with > [string] and other [types], I have not solved my problem. > > Here is a version that does work perfectly well, but I love employing > variables. > > ---------------------------------------------------------------------------*----------------------------------- > > get-wmiobject -query "select DeviceId, Status, MediaType, Size, FreeSpace > from win32_logicaldisk"` > > |sort | format-table DeviceId, MediaType, Size, FreeSpace -groupby > MediaType -auto > > Can you help get it working with a $Item variable? > > Guy You should make your variable an array, because that is what is passed to format-table when you use the literal syntax, e.g.: $item = @("DeviceId", "MediaType", "Size", "FreeSpace") get-wmiobject -query "Select $Item from win32_logicaldisk" ` | sort mediatype | format-table $Item -auto -groupby MediaType Hope this helps, - Oisin Dear Oisin I thank you. The array worked as you said it would. The only problem is that I (we) cannot make one variable work for both the -query and the format-table. - or can we? ------------------------------------------------------------------------------------------ $Seln = "DeviceId, MediaType, Size, FreeSpace" $Item = @("DeviceId", "MediaType", "Size", "FreeSpace") get-wmiobject -query "Select $Seln from win32_logicaldisk"` |sort mediatype | format-table $Item -auto -groupby MediaType ------------------------------------------------------------------------------------------ Is there anyway of using just one variable, instead of both $Seln and $Item? Guy |
| | #4 (permalink) |
| Guest | Re: $Variables > ------------------------------------------------------------------------------------------ > > $Seln = "DeviceId, MediaType, Size, FreeSpace" > > $Item = @("DeviceId", "MediaType", "Size", "FreeSpace") > > get-wmiobject -query "Select $Seln from win32_logicaldisk"` > > |sort mediatype | format-table $Item -auto -groupby MediaType > > ------------------------------------------------------------------------------------------ > > Is there anyway of using just one variable, instead of both $Seln and > $Item? Well.... you could always try creating $Seln from $Item: PS C:\> $Item = @("DeviceId", "MediaType", "Size", "FreeSpace") PS C:\> $seln = [string]::Join(",", $Item) PS C:\> $seln DeviceId,MediaType,Size,FreeSpace "Guy Thomas" <guy@computerperformance.co.uk> wrote in message news:u5iFOQ6oHHA.3952@TK2MSFTNGP03.phx.gbl... > > "Oisin Grehan" <oising@gmail.com> wrote in message > news:1180619962.555154.39380@q69g2000hsb.googlegroups.com... > On May 31, 9:02 am, "Guy Thomas" <g...@computerperformance.co.uk> > wrote: >> I have been trying to use a $variable to control my format-table command. >> >> ---------------------------------------------------------------------------*------------------------------ >> >> $Item = "DeviceId, MediaType, Size, FreeSpace" >> >> get-wmiobject -query "Select $Item from win32_logicaldisk" ` >> >> |sort mediatype | format-table $Item -auto -groupby MediaType >> >> # |sort mediatype | format-table >> $ExecutionContext.InvokeCommand.ExpandString($Item) -auto -groupby >> MediaType >> >> ---------------------------------------------------------------------------*----------------------------------- >> >> As you can see from the remmed out line I have been trying a variety of >> techniques. While I have learnt a lot about , >> $ExecutionContext.InvokeCommand.ExpandString and defining variables with >> [string] and other [types], I have not solved my problem. >> >> Here is a version that does work perfectly well, but I love employing >> variables. >> >> ---------------------------------------------------------------------------*----------------------------------- >> >> get-wmiobject -query "select DeviceId, Status, MediaType, Size, >> FreeSpace >> from win32_logicaldisk"` >> >> |sort | format-table DeviceId, MediaType, Size, FreeSpace -groupby >> MediaType -auto >> >> Can you help get it working with a $Item variable? >> >> Guy > > You should make your variable an array, because that is what is passed > to format-table when you use the literal syntax, e.g.: > > $item = @("DeviceId", "MediaType", "Size", "FreeSpace") > > get-wmiobject -query "Select $Item from win32_logicaldisk" ` > | sort mediatype | format-table $Item -auto -groupby MediaType > > Hope this helps, > > - Oisin > > Dear Oisin > > I thank you. The array worked as you said it would. The only problem is > that I (we) cannot make one variable work for both the -query and the > format-table. - or can we? > > ------------------------------------------------------------------------------------------ > > $Seln = "DeviceId, MediaType, Size, FreeSpace" > > $Item = @("DeviceId", "MediaType", "Size", "FreeSpace") > > get-wmiobject -query "Select $Seln from win32_logicaldisk"` > > |sort mediatype | format-table $Item -auto -groupby MediaType > > ------------------------------------------------------------------------------------------ > > Is there anyway of using just one variable, instead of both $Seln and > $Item? > > Guy > > |
| | #5 (permalink) |
| Guest | Re: $Variables Here is what I got to work $Item = @("DeviceId", "MediaType", "Size", "FreeSpace") # this is one long line if it should wrap get-wmiobject -query "Select $([string]::Join(',',$Item)) from win32_logicaldisk" |Format-Table $item -auto -groupby MediaType "Guy Thomas" <guy@computerperformance.co.uk> wrote in message news:u5iFOQ6oHHA.3952@TK2MSFTNGP03.phx.gbl... > > "Oisin Grehan" <oising@gmail.com> wrote in message > news:1180619962.555154.39380@q69g2000hsb.googlegroups.com... > On May 31, 9:02 am, "Guy Thomas" <g...@computerperformance.co.uk> > wrote: >> I have been trying to use a $variable to control my format-table command. >> >> ---------------------------------------------------------------------------*------------------------------ >> >> $Item = "DeviceId, MediaType, Size, FreeSpace" >> >> get-wmiobject -query "Select $Item from win32_logicaldisk" ` >> >> |sort mediatype | format-table $Item -auto -groupby MediaType >> >> # |sort mediatype | format-table >> $ExecutionContext.InvokeCommand.ExpandString($Item) -auto -groupby >> MediaType >> >> ---------------------------------------------------------------------------*----------------------------------- >> >> As you can see from the remmed out line I have been trying a variety of >> techniques. While I have learnt a lot about , >> $ExecutionContext.InvokeCommand.ExpandString and defining variables with >> [string] and other [types], I have not solved my problem. >> >> Here is a version that does work perfectly well, but I love employing >> variables. >> >> ---------------------------------------------------------------------------*----------------------------------- >> >> get-wmiobject -query "select DeviceId, Status, MediaType, Size, >> FreeSpace >> from win32_logicaldisk"` >> >> |sort | format-table DeviceId, MediaType, Size, FreeSpace -groupby >> MediaType -auto >> >> Can you help get it working with a $Item variable? >> >> Guy > > You should make your variable an array, because that is what is passed > to format-table when you use the literal syntax, e.g.: > > $item = @("DeviceId", "MediaType", "Size", "FreeSpace") > > get-wmiobject -query "Select $Item from win32_logicaldisk" ` > | sort mediatype | format-table $Item -auto -groupby MediaType > > Hope this helps, > > - Oisin > > Dear Oisin > > I thank you. The array worked as you said it would. The only problem is > that I (we) cannot make one variable work for both the -query and the > format-table. - or can we? > > ------------------------------------------------------------------------------------------ > > $Seln = "DeviceId, MediaType, Size, FreeSpace" > > $Item = @("DeviceId", "MediaType", "Size", "FreeSpace") > > get-wmiobject -query "Select $Seln from win32_logicaldisk"` > > |sort mediatype | format-table $Item -auto -groupby MediaType > > ------------------------------------------------------------------------------------------ > > Is there anyway of using just one variable, instead of both $Seln and > $Item? > > Guy > > |
| | #6 (permalink) |
| Guest | Re: $Variables Dear Oisin, Marcel and Brandon Your responses were fantastic - needless to say they worked a treat. I am still at that 'little boy thrilled with new toy' stage of scripting with PowerShell. I would also like to take this opportunity to say what a friendly, focused forum this is. Guy "Guy Thomas" <guy@computerperformance.co.uk> wrote in message news:u5iFOQ6oHHA.3952@TK2MSFTNGP03.phx.gbl... > > "Oisin Grehan" <oising@gmail.com> wrote in message > news:1180619962.555154.39380@q69g2000hsb.googlegroups.com... > On May 31, 9:02 am, "Guy Thomas" <g...@computerperformance.co.uk> > wrote: >> I have been trying to use a $variable to control my format-table command. >> >> ---------------------------------------------------------------------------*------------------------------ >> >> $Item = "DeviceId, MediaType, Size, FreeSpace" >> >> get-wmiobject -query "Select $Item from win32_logicaldisk" ` >> >> |sort mediatype | format-table $Item -auto -groupby MediaType >> >> # |sort mediatype | format-table >> $ExecutionContext.InvokeCommand.ExpandString($Item) -auto -groupby >> MediaType >> >> ---------------------------------------------------------------------------*----------------------------------- >> >> As you can see from the remmed out line I have been trying a variety of >> techniques. While I have learnt a lot about , >> $ExecutionContext.InvokeCommand.ExpandString and defining variables with >> [string] and other [types], I have not solved my problem. >> >> Here is a version that does work perfectly well, but I love employing >> variables. >> >> ---------------------------------------------------------------------------*----------------------------------- >> >> get-wmiobject -query "select DeviceId, Status, MediaType, Size, >> FreeSpace >> from win32_logicaldisk"` >> >> |sort | format-table DeviceId, MediaType, Size, FreeSpace -groupby >> MediaType -auto >> >> Can you help get it working with a $Item variable? >> >> Guy > > You should make your variable an array, because that is what is passed > to format-table when you use the literal syntax, e.g.: > > $item = @("DeviceId", "MediaType", "Size", "FreeSpace") > > get-wmiobject -query "Select $Item from win32_logicaldisk" ` > | sort mediatype | format-table $Item -auto -groupby MediaType > > Hope this helps, > > - Oisin > > Dear Oisin > > I thank you. The array worked as you said it would. The only problem is > that I (we) cannot make one variable work for both the -query and the > format-table. - or can we? > > ------------------------------------------------------------------------------------------ > > $Seln = "DeviceId, MediaType, Size, FreeSpace" > > $Item = @("DeviceId", "MediaType", "Size", "FreeSpace") > > get-wmiobject -query "Select $Seln from win32_logicaldisk"` > > |sort mediatype | format-table $Item -auto -groupby MediaType > > ------------------------------------------------------------------------------------------ > > Is there anyway of using just one variable, instead of both $Seln and > $Item? > > Guy > > |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| not using variables | IT Staff | PowerShell | 1 | 01-09-2007 09:50 PM |
| Re: list env variables | Keith Hill | PowerShell | 4 | 01-04-2007 11:23 AM |
| Should this work with variables | Marco Shaw | PowerShell | 2 | 12-04-2006 10:29 AM |
| Sundeep Raina(Iopsis): Is variables being handled in Workflow and How to declare New Variables | sunny | Avalon | 0 | 06-30-2006 01:31 AM |