Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - WMI - How to process thru subdirectories for my script

Reply
 
Old 09-15-2008   #1 (permalink)
Ripp


 
 

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 SpecsSystem Spec
Old 09-15-2008   #2 (permalink)
Ripp


 
 

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 SpecsSystem Spec
Old 09-15-2008   #3 (permalink)
tojo2000


 
 

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
> > * * * * * * * * * *}
> > * *}
This might be a good place to use recursion. Make a function that
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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46