![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | WMI - How to process thru subdirectories for my script Hi All, Here is a script I'm working on and I was hoping someone could help point me in the right direction. I want the following script to be able to process through a directory and all subdirectories reporting on certain files. I can report on a specific directory no problem. I have to use WMI for the credentail option. Here is the test script i'm using. ## Declare variables $passwordfile = "c:\scripts\password.txt" $easeWorkstationsFile = "c:\scripts\ease-workstations.txt" ## Functions function PingWorkstation { Param($hostIP) $pingresult = Get-WmiObject win32_pingstatus -f "address='$hostIP'" if($pingresult.statuscode -eq 0) {$true} else {$false} } ## Create the username and password credential object $username = "administrator" $password = Get-Content $passwordfile | ConvertTo-SecureString $credential = New-Object System.Management.Automation.PsCredential ` "administrator", $password ## Read in EASE workstation IPs $workstationIPs = get-content $easeWorkstationsFile ## Process through the EASE workstation IPs foreach ($ip in $workstationIPs) { if (PingWorkstation $ip) { "-------------------" $ip $files = get-wmiobject cim_Logicalfile -computer $ip ` -credential $credential -filter "Drive ='c:' ` AND Extension = 'exe' AND path = '\\dell\\'" $files | select-object name, installdate, lastaccessed, lastmodified, filesize } } |
My System Specs![]() |
| | #2 (permalink) |
| | RE: WMI - How to process thru subdirectories for my script In doing some investigation it looks like i can use the filetype property to determine if a folder or not and build a routine to start at the top most directory and work my way down. If you have an easier way, please share =) "Ripp" wrote: Quote: > Hi All, > > Here is a script I'm working on and I was hoping someone could help point me > in the right direction. I want the following script to be able to process > through a directory and all subdirectories reporting on certain files. I can > report on a specific directory no problem. I have to use WMI for the > credentail option. Here is the test script i'm using. > > ## Declare variables > $passwordfile = "c:\scripts\password.txt" > $easeWorkstationsFile = "c:\scripts\ease-workstations.txt" > > ## Functions > function PingWorkstation > { > Param($hostIP) > $pingresult = Get-WmiObject win32_pingstatus -f "address='$hostIP'" > if($pingresult.statuscode -eq 0) {$true} else {$false} > } > > ## Create the username and password credential object > $username = "administrator" > $password = Get-Content $passwordfile | ConvertTo-SecureString > $credential = New-Object System.Management.Automation.PsCredential ` > "administrator", $password > > ## Read in EASE workstation IPs > $workstationIPs = get-content $easeWorkstationsFile > > ## Process through the EASE workstation IPs > foreach ($ip in $workstationIPs) > { > if (PingWorkstation $ip) > { > "-------------------" > $ip > $files = get-wmiobject cim_Logicalfile -computer $ip ` > -credential $credential -filter "Drive ='c:' ` > AND Extension = 'exe' AND path = '\\dell\\'" > $files | select-object name, installdate, lastaccessed, lastmodified, > filesize > } > } > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: WMI - How to process thru subdirectories for my script On Sep 15, 8:26*am, Ripp <R...@xxxxxx> wrote: Quote: > In doing some investigation it looks like i can use the filetype propertyto > determine if a folder or not and build a routine to start at the top most > directory and work my way down. *If you have an easier way, please share * =) > > "Ripp" wrote: Quote: > > Hi All, Quote: > > Here is a script I'm working on and I was hoping someone could help point me > > in the right direction. *I want the following script to be able to process > > through a directory and all subdirectories reporting on certain files. *I can > > report on a specific directory no problem. *I have to use WMI for the > > credentail option. *Here is the test script i'm using. Quote: > > ## *Declare variables > > $passwordfile = "c:\scripts\password.txt" > > $easeWorkstationsFile = "c:\scripts\ease-workstations.txt" Quote: > > ## *Functions > > function PingWorkstation > > * *{ > > * *Param($hostIP) > > * * $pingresult = Get-WmiObject win32_pingstatus -f "address='$hostIP'" > > * * if($pingresult.statuscode -eq 0) {$true} else {$false} > > * * } Quote: > > ## *Create the username and password credential object > > $username = "administrator" > > $password = Get-Content $passwordfile | ConvertTo-SecureString > > $credential = New-Object System.Management.Automation.PsCredential ` > > * *"administrator", $password Quote: > > ## *Read in EASE workstation IPs > > $workstationIPs = get-content $easeWorkstationsFile Quote: > > ## *Process through the EASE workstation IPs > > foreach ($ip in $workstationIPs) > > * *{ > > * * * * * *if (PingWorkstation $ip) > > * * * * * * * * * *{ > > * * * * * * * * * *"-------------------" > > * * * * * * * * * *$ip > > * * * * * * * * * *$files = get-wmiobject cim_Logicalfile -computer $ip ` > > * * * * * * * * * *-credential $credential -filter "Drive ='c:' ` > > * * * * * * * * * *AND Extension = 'exe' AND path= '\\dell\\'" > > * * * * * * * * * *$files | select-object name, installdate, lastaccessed, lastmodified, > > filesize > > * * * * * * * * * *} > > * *} takes a folder name as an argument and gets the files, and as it processes the files have it call itself on the file if that file is also a folder. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Recursively check subdirectories | PowerShell | |||
| Playing with empty subdirectories | PowerShell | |||
| Batch script not waiting for process to end in Vista | Vista General | |||
| How to write a script to process it as a task? | PowerShell | |||
| Pause script until process id on remote machine goes away? | PowerShell | |||