![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| | |||||||
| | Vista - How do you use .net enumeration values in powershell? |
| |
| 09-20-2007 | #1 (permalink) |
| | How do you use .net enumeration values in powershell? I am trying to read the file attributes given a file or folder. What I expected to be simple is unfortunately not giving me the results I expected. ## This returns the type FileAttributes (Get-ChildItem | % {$_.get_attributes()})[0].gettype() ## This does not produce the results that I get by executing cmd /c dir /aa; nothing is printed on the screen Get-ChildItem | % {if ($_.get_attributes() -band [System.IO.FileAttributes].Archive) {echo 'yes'} } ## This results in a nul expression $a = [System.IO.FileAttributes].Archive $a -eq $null So my problem appears to be because I don't understand how to access .NET enumeration types. I would appreciate someone explaining to me how I can do this. thx bob |
| My System Specs |
| 09-20-2007 | #2 (permalink) |
| | Re: How do you use .net enumeration values in powershell? On Sep 20, 9:06 pm, Bob Landau <BobLan...@xxxxxx> wrote: Quote: > I am trying to read the file attributes given a file or folder. What I > expected to be simple is unfortunately not giving me the results I expected. > > ## This returns the type FileAttributes > (Get-ChildItem | % {$_.get_attributes()})[0].gettype() > > ## This does not produce the results that I get by executing cmd /c dir /aa; > nothing is printed on the screen > Get-ChildItem | % {if ($_.get_attributes() -band > [System.IO.FileAttributes].Archive) {echo 'yes'} } > > ## This results in a nul expression > $a = [System.IO.FileAttributes].Archive > > $a -eq $null > > So my problem appears to be because I don't understand how to access .NET > enumeration types. I would appreciate someone explaining to me how I can do > this. > > thx > bob $a = [System.IO.FileAttributes]::Archive or $a = [System.IO.FileAttributes] "Archive" Good luck. Jeff |
| My System Specs |
| 09-20-2007 | #3 (permalink) |
| | Re: How do you use .net enumeration values in powershell? Bit by "static" again. I was familar with static method/properties. In hindsight it seems obvious that static should apply to enum types. Thank you bob "Jeff" wrote: Quote: > On Sep 20, 9:06 pm, Bob Landau <BobLan...@xxxxxx> > wrote: Quote: > > I am trying to read the file attributes given a file or folder. What I > > expected to be simple is unfortunately not giving me the results I expected. > > > > ## This returns the type FileAttributes > > (Get-ChildItem | % {$_.get_attributes()})[0].gettype() > > > > ## This does not produce the results that I get by executing cmd /c dir /aa; > > nothing is printed on the screen > > Get-ChildItem | % {if ($_.get_attributes() -band > > [System.IO.FileAttributes].Archive) {echo 'yes'} } > > > > ## This results in a nul expression > > $a = [System.IO.FileAttributes].Archive > > > > $a -eq $null > > > > So my problem appears to be because I don't understand how to access .NET > > enumeration types. I would appreciate someone explaining to me how I can do > > this. > > > > thx > > bob > Try this: > > $a = [System.IO.FileAttributes]::Archive > or > $a = [System.IO.FileAttributes] "Archive" > > Good luck. > > Jeff > > |
| My System Specs |
| 09-20-2007 | #4 (permalink) |
| | Re: How do you use .net enumeration values in powershell? BTW, Installing MoW's PowerTab can save you a lot of "if and how", It did for me ![]() Shay http://scriptolog.blogspot.com Quote: > Bit by "static" again. > > I was familar with static method/properties. In hindsight it seems > obvious that static should apply to enum types. > > Thank you > > bob > > "Jeff" wrote: > Quote: >> On Sep 20, 9:06 pm, Bob Landau <BobLan...@xxxxxx> >> wrote: >> Quote: >>> I am trying to read the file attributes given a file or folder. What >>> I expected to be simple is unfortunately not giving me the results I >>> expected. >>> >>> ## This returns the type FileAttributes >>> (Get-ChildItem | % {$_.get_attributes()})[0].gettype() >>> ## This does not produce the results that I get by executing cmd /c >>> dir /aa; >>> nothing is printed on the screen >>> Get-ChildItem | % {if ($_.get_attributes() -band >>> [System.IO.FileAttributes].Archive) {echo 'yes'} } >>> ## This results in a nul expression >>> $a = [System.IO.FileAttributes].Archive >>> $a -eq $null >>> >>> So my problem appears to be because I don't understand how to access >>> .NET enumeration types. I would appreciate someone explaining to me >>> how I can do this. >>> >>> thx >>> bob >> >> $a = [System.IO.FileAttributes]::Archive >> or >> $a = [System.IO.FileAttributes] "Archive" >> Good luck. >> >> Jeff >> |
| My System Specs |
![]() |
| Thread Tools | |
| |
| Similar Threads for: How do you use .net enumeration values in powershell? | ||||
| Thread | Forum | |||
| Using Powershell to search the registry for all Keys, Values, and | PowerShell | |||
| Read values returned from a powershell command in VB.Net | PowerShell | |||
| mirroringrole enumeration - script | PowerShell | |||
| Combining enumeration values | PowerShell | |||
| Networok Enumeration | Vista networking & sharing | |||