Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
also, the speed was very quick and I couldn't ask for it to be any quicker. I'm just not sure how to search for that file in any local disk of a particular server.
Also, how do I date format and truncate the "LastModified"?
I am going to stress this very heavily Dee. You really need to get a book or take a class in PowerShell. YOu are asing questions about each lin eof code. Many of these questions you are very close to having an answer for but it appears you lack some of the fundamentals. Save yourseld some frustration and get one of the many books on programming PowerShell.
The answer to your last questin is that you can't do it the way you are approaching the problem. You need to handle the property selection and formating manually in code in this case. The objects returned by WMI are not always complpetely decoded into NET types and you need to do this yourself. The ConvertToDateTime method I posted was a hint. It is one of the ways that WMI has been modified in NET and PoSH to make it more usable/convenient. You still need to do the individual programming steps.
To search through all disks of a server you would need to change teh dirve letter of the search or not use a drive letter. Using a drive letter an full path will be very fast. Not using a drive letter but using a full path will be very fast assumming no more that 10 disks.
To search across all disks use "filename=" instead of "name=". When using filename use only teh first part without the extension. Specifiy extension separately.
To get a list of all volumes try the following:
gwmi -query "select * from Win32_LogicalDisk where drivetype=3"|%{$_.Name}
You can use strin gmanipulation to add teh volume name to the file name so you can search through all local drives. If you need to search USB and other odd drive types then you will need to modify teh WHERE to include the correct types.
PS> Get-WmiObject -Query "SELECT * FROM cim_datafile where filename='boot'"
Compressed : False
Encrypted : False
Size :
Hidden : True
Name : <FONT color=#cc0000>c:boot.ini</FONT>
Readable : True
System File :
Version :
Writeable : False
Compressed : False
Encrypted : False
Size :
Hidden : False
Name : d:boot.ini
Readable : True
System File :
Version :
Writeable : True
Compressed : False
Encrypted : False
Size :
Hidden : False
Name : d:boot.txt
Readable : True
System File :
Version :
Writeable : True
The above query returns all files on all drives with teh "filename" "boot". If I add teh extension like this:
PS> Get-WmiObject -Query "SELECT * FROM cim_datafile where filename='boot' AND Extension='ini'"
We will get only files with an ini extension from all local drives. This will return only two file objects from the above example.
This will allow searching for a file by name on all installed drives but will take a long time due to the need to scan all files on all drives. Adding teh path will restrict this so it will be much faster.
PS> Get-WmiObject -Query "SELECT * FROM cim_datafile where filename='boot' AND Extension='ini' AND Path='fold1fold2'"
I am going to stress this very heavily Dee. You really need to get a book or take a class in PowerShell. YOu are asing questions about each lin eof code. Many of these questions you are very close to having an answer for but it appears you lack some of the fundamentals. Save yourseld some frustration and get one of the many books on programming PowerShell.
Not frustrated here. But, it seems like you are frustrated with me. Sorry I won't bother you again. Maybe others might be willing to assistant on this site.
If you don't want to help don't and you don't need to insult me and say I lack the fundamentals and need formal training. I am new to powershell. I don't see anywhere on this site saying you can't ask newbie questions.. how-TOs, etc. If you are not interested then just don't answer.
Okay - let me reiterate the policy on this Web site. If you see a question you don't want to answer, then DON'T ANSWER IT. However, if you choose to answer - then ANSWER. If you'd like to politely suggest that a particular book might be helpful, then please do so - suggest a PARTICULAR book. However, please ensure that you're not coming across as insulting. People come here for help, not a brush-off.
Dee, please consider that some folks have a harder time expressing themselves in writing. What they write as a polite suggestion can come across as a brush-off to someone else.
Get-WmiObject -Query "SELECT * FROM cim_datafile where name='c:program filesesetupdfileslastupd.ver'" -ComputerName $_ -Credential $cred |
Select-Object Name,@{Name="LastModified";Expression={$_.ConvertToDateTime($_.LastModified)}} | Format-List
Now instead of showing "LastModified : 20080428114231.585250-300" it shows "LastModified : 4/28/2008 12:42:34 PM instead. Just the way I want it. I'm proud of myself. LOL!
No problem. I've learned allot from you and scriptinganswers.com's posts. Good Job! I've come a long way since my 1st post on here, so i'm greatly appreciative of all you do here.
Know of a way to retrieve the scheduled tasks runas logon account of remote servers? I tried via the Win32_ScheduleJob, but it looks like it only works if it was created via AT. Otherwise it shows blank. Any ideas? Thank you so much for all your help!
Dee
This topic is 15 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.