PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > output to a file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
output to a file

Réponse
 
LinkBack Outils de la discussion
Vieux 21/11/2007, 14h02   #1
LMac
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut output to a file

Hi

I need to output a list of pst files from a server into a text file. I have
found this script which will show on screen the files but unable to find out
how to export the list to a txt file. Can this be done?

Thanks

----------------------------------------------------
Option Explicit

Dim fso, objF, d, dc
Dim objWMIService, colFiles, objFile
Dim FileSizeKB, FileSizeMB, FileSizeGB

Set objWMIService = _
GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")

Set fso = CreateObject("Scripting.FileSystemObject")

Set dc = fso.Drives

For Each d in dc

if d.DriveType = 2 then 'fixed drives only

Set colFiles = objWMIService.ExecQuery("Select * from " & _
"CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
"and (Extension = 'pst')")
For Each objFile in colFiles

'1KB = 1024 bytes
FileSizeKB = objFile.FileSize \ 1024
'1MB = 1024 * 1024 bytes (1KB * 1024)
FileSizeMB = objFile.FileSize \ 1024 \ 1024
'1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
If FileSizeGB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
ElseIf FileSizeMB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
ElseIf FileSizeKB >= 1 Then
Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
Else
Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
End If

Next

end if

Next

  Réponse avec citation
Vieux 21/11/2007, 14h46   #2
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: output to a file

Run the script at a command prompt with the cscript host and redirect the
output to a text file. For example if the script is called FindPst.vbs:

cscript //nologo FindPst.vbs > report.txt

This assumes you are in the directory where the file FindPst.vbs is saved.
Otherwise specify the full path. The //nologo option suppresses logo
information. The file report.txt is created in the current directory.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"LMac" <LMac@discussions.microsoft.com> wrote in message
news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
> Hi
>
> I need to output a list of pst files from a server into a text file. I
> have
> found this script which will show on screen the files but unable to find
> out
> how to export the list to a txt file. Can this be done?
>
> Thanks
>
> ----------------------------------------------------
> Option Explicit
>
> Dim fso, objF, d, dc
> Dim objWMIService, colFiles, objFile
> Dim FileSizeKB, FileSizeMB, FileSizeGB
>
> Set objWMIService = _
> GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> Set dc = fso.Drives
>
> For Each d in dc
>
> if d.DriveType = 2 then 'fixed drives only
>
> Set colFiles = objWMIService.ExecQuery("Select * from " & _
> "CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
> "and (Extension = 'pst')")
> For Each objFile in colFiles
>
> '1KB = 1024 bytes
> FileSizeKB = objFile.FileSize \ 1024
> '1MB = 1024 * 1024 bytes (1KB * 1024)
> FileSizeMB = objFile.FileSize \ 1024 \ 1024
> '1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
> FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
> If FileSizeGB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
> ElseIf FileSizeMB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
> ElseIf FileSizeKB >= 1 Then
> Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
> Else
> Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
> End If
>
> Next
>
> end if
>
> Next
>



  Réponse avec citation
Vieux 21/11/2007, 15h25   #3
LMac
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: output to a file

Thanks for the info.

Also, Is it possible to run this script for a number of servers and output
the info into one file run through a scheduled task. I would be looking to
search a specific location for each server e.g.
\\servera\users
\\serverb\users
\\serverc\users
Or would it be better running a different scheduled task on each server
outputting to a different file each time?

"Richard Mueller [MVP]" wrote:

> Run the script at a command prompt with the cscript host and redirect the
> output to a text file. For example if the script is called FindPst.vbs:
>
> cscript //nologo FindPst.vbs > report.txt
>
> This assumes you are in the directory where the file FindPst.vbs is saved.
> Otherwise specify the full path. The //nologo option suppresses logo
> information. The file report.txt is created in the current directory.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "LMac" <LMac@discussions.microsoft.com> wrote in message
> news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
> > Hi
> >
> > I need to output a list of pst files from a server into a text file. I
> > have
> > found this script which will show on screen the files but unable to find
> > out
> > how to export the list to a txt file. Can this be done?
> >
> > Thanks
> >
> > ----------------------------------------------------
> > Option Explicit
> >
> > Dim fso, objF, d, dc
> > Dim objWMIService, colFiles, objFile
> > Dim FileSizeKB, FileSizeMB, FileSizeGB
> >
> > Set objWMIService = _
> > GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
> >
> > Set fso = CreateObject("Scripting.FileSystemObject")
> >
> > Set dc = fso.Drives
> >
> > For Each d in dc
> >
> > if d.DriveType = 2 then 'fixed drives only
> >
> > Set colFiles = objWMIService.ExecQuery("Select * from " & _
> > "CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
> > "and (Extension = 'pst')")
> > For Each objFile in colFiles
> >
> > '1KB = 1024 bytes
> > FileSizeKB = objFile.FileSize \ 1024
> > '1MB = 1024 * 1024 bytes (1KB * 1024)
> > FileSizeMB = objFile.FileSize \ 1024 \ 1024
> > '1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
> > FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
> > If FileSizeGB >= 1 Then
> > Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
> > ElseIf FileSizeMB >= 1 Then
> > Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
> > ElseIf FileSizeKB >= 1 Then
> > Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
> > Else
> > Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
> > End If
> >
> > Next
> >
> > end if
> >
> > Next
> >

>
>
>

  Réponse avec citation
Vieux 21/11/2007, 17h03   #4
Richard Mueller [MVP]
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: output to a file

The script you posted is designed to be run on the local computer. The
statement:

Set objWMIService = _
GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")

connects to the local computer. The "\\." in the path means to default to
the local computer. If you substitute the NetBIOS name of a computer (local
or remote) for the".", the script will connect to that computer (if you have
permissions and connectivity). You can run your script in a loop, once for
each computer in an array. Something similar to (watch line wrappting):
============
arrServers = Array("servera", "serverb", "serverc")

For Each strServer In arrServers
' code for each server.
' ...
Set objWMIService = _
GetObject("winmgmts:{impersonationLevel=impersonat e}!\\" & strServer
& "\root\cimv2")
' ...
Next
===========
However, the code in your script that retrieves drives will only work on the
local computer. The FileSystemObject cannot retrieve drives on the remote
computer. Instead you can use the WMI Win32_LogicalDisk class. See the link
for details and examples:

http://www.microsoft.com/technet/scr..._fsd_zinq.mspx

You can navigate in the TOC at the left for examples. You will need to use
the Win32_LogicalDisk class to enumerate all drives (of DriveType=3, which
is local hard disks), then for each drive use your code to look just at
files with the specified extension. The same objWMIService object reference
is used to retrieve the drives and also the files.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"LMac" <LMac@discussions.microsoft.com> wrote in message
news:70A0565B-F96F-462E-8394-28D447EFCC96@microsoft.com...
> Thanks for the info.
>
> Also, Is it possible to run this script for a number of servers and output
> the info into one file run through a scheduled task. I would be looking
> to
> search a specific location for each server e.g.
> \\servera\users
> \\serverb\users
> \\serverc\users
> Or would it be better running a different scheduled task on each server
> outputting to a different file each time?
>
> "Richard Mueller [MVP]" wrote:
>
>> Run the script at a command prompt with the cscript host and redirect the
>> output to a text file. For example if the script is called FindPst.vbs:
>>
>> cscript //nologo FindPst.vbs > report.txt
>>
>> This assumes you are in the directory where the file FindPst.vbs is
>> saved.
>> Otherwise specify the full path. The //nologo option suppresses logo
>> information. The file report.txt is created in the current directory.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> "LMac" <LMac@discussions.microsoft.com> wrote in message
>> news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
>> > Hi
>> >
>> > I need to output a list of pst files from a server into a text file. I
>> > have
>> > found this script which will show on screen the files but unable to
>> > find
>> > out
>> > how to export the list to a txt file. Can this be done?
>> >
>> > Thanks
>> >
>> > ----------------------------------------------------
>> > Option Explicit
>> >
>> > Dim fso, objF, d, dc
>> > Dim objWMIService, colFiles, objFile
>> > Dim FileSizeKB, FileSizeMB, FileSizeGB
>> >
>> > Set objWMIService = _
>> > GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
>> >
>> > Set fso = CreateObject("Scripting.FileSystemObject")
>> >
>> > Set dc = fso.Drives
>> >
>> > For Each d in dc
>> >
>> > if d.DriveType = 2 then 'fixed drives only
>> >
>> > Set colFiles = objWMIService.ExecQuery("Select * from " & _
>> > "CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
>> > "and (Extension = 'pst')")
>> > For Each objFile in colFiles
>> >
>> > '1KB = 1024 bytes
>> > FileSizeKB = objFile.FileSize \ 1024
>> > '1MB = 1024 * 1024 bytes (1KB * 1024)
>> > FileSizeMB = objFile.FileSize \ 1024 \ 1024
>> > '1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
>> > FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
>> > If FileSizeGB >= 1 Then
>> > Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
>> > ElseIf FileSizeMB >= 1 Then
>> > Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
>> > ElseIf FileSizeKB >= 1 Then
>> > Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
>> > Else
>> > Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
>> > End If
>> >
>> > Next
>> >
>> > end if
>> >
>> > Next
>> >

>>
>>
>>



  Réponse avec citation
Vieux 29/11/2007, 11h09   #5
LMac
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: output to a file

How would I run this as a scheduled task?

cscript //nologo FindPst.vbs > report.txt


"LMac" wrote:

> Thanks for the info.
>
> Also, Is it possible to run this script for a number of servers and output
> the info into one file run through a scheduled task. I would be looking to
> search a specific location for each server e.g.
> \\servera\users
> \\serverb\users
> \\serverc\users
> Or would it be better running a different scheduled task on each server
> outputting to a different file each time?
>
> "Richard Mueller [MVP]" wrote:
>
> > Run the script at a command prompt with the cscript host and redirect the
> > output to a text file. For example if the script is called FindPst.vbs:
> >
> > cscript //nologo FindPst.vbs > report.txt
> >
> > This assumes you are in the directory where the file FindPst.vbs is saved.
> > Otherwise specify the full path. The //nologo option suppresses logo
> > information. The file report.txt is created in the current directory.
> >
> > --
> > Richard Mueller
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> > "LMac" <LMac@discussions.microsoft.com> wrote in message
> > news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
> > > Hi
> > >
> > > I need to output a list of pst files from a server into a text file. I
> > > have
> > > found this script which will show on screen the files but unable to find
> > > out
> > > how to export the list to a txt file. Can this be done?
> > >
> > > Thanks
> > >
> > > ----------------------------------------------------
> > > Option Explicit
> > >
> > > Dim fso, objF, d, dc
> > > Dim objWMIService, colFiles, objFile
> > > Dim FileSizeKB, FileSizeMB, FileSizeGB
> > >
> > > Set objWMIService = _
> > > GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
> > >
> > > Set fso = CreateObject("Scripting.FileSystemObject")
> > >
> > > Set dc = fso.Drives
> > >
> > > For Each d in dc
> > >
> > > if d.DriveType = 2 then 'fixed drives only
> > >
> > > Set colFiles = objWMIService.ExecQuery("Select * from " & _
> > > "CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
> > > "and (Extension = 'pst')")
> > > For Each objFile in colFiles
> > >
> > > '1KB = 1024 bytes
> > > FileSizeKB = objFile.FileSize \ 1024
> > > '1MB = 1024 * 1024 bytes (1KB * 1024)
> > > FileSizeMB = objFile.FileSize \ 1024 \ 1024
> > > '1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
> > > FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
> > > If FileSizeGB >= 1 Then
> > > Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
> > > ElseIf FileSizeMB >= 1 Then
> > > Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
> > > ElseIf FileSizeKB >= 1 Then
> > > Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
> > > Else
> > > Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
> > > End If
> > >
> > > Next
> > >
> > > end if
> > >
> > > Next
> > >

> >
> >
> >

  Réponse avec citation
Vieux 30/11/2007, 18h46   #6
Al Dunbar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: output to a file

One way would be to schedule a batch file (or CMD script ;-) that contains
the command you want to run.

/Al

"LMac" <LMac@discussions.microsoft.com> wrote in message
news:01956639-573D-4A27-8C45-086393F9D3EF@microsoft.com...
> How would I run this as a scheduled task?
>
> cscript //nologo FindPst.vbs > report.txt
>
>
> "LMac" wrote:
>
>> Thanks for the info.
>>
>> Also, Is it possible to run this script for a number of servers and
>> output
>> the info into one file run through a scheduled task. I would be looking
>> to
>> search a specific location for each server e.g.
>> \\servera\users
>> \\serverb\users
>> \\serverc\users
>> Or would it be better running a different scheduled task on each server
>> outputting to a different file each time?
>>
>> "Richard Mueller [MVP]" wrote:
>>
>> > Run the script at a command prompt with the cscript host and redirect
>> > the
>> > output to a text file. For example if the script is called FindPst.vbs:
>> >
>> > cscript //nologo FindPst.vbs > report.txt
>> >
>> > This assumes you are in the directory where the file FindPst.vbs is
>> > saved.
>> > Otherwise specify the full path. The //nologo option suppresses logo
>> > information. The file report.txt is created in the current directory.
>> >
>> > --
>> > Richard Mueller
>> > Microsoft MVP Scripting and ADSI
>> > Hilltop Lab - http://www.rlmueller.net
>> > --
>> >
>> > "LMac" <LMac@discussions.microsoft.com> wrote in message
>> > news:0C2F0A09-DD34-43CA-B632-C9E7C5933E08@microsoft.com...
>> > > Hi
>> > >
>> > > I need to output a list of pst files from a server into a text file.
>> > > I
>> > > have
>> > > found this script which will show on screen the files but unable to
>> > > find
>> > > out
>> > > how to export the list to a txt file. Can this be done?
>> > >
>> > > Thanks
>> > >
>> > > ----------------------------------------------------
>> > > Option Explicit
>> > >
>> > > Dim fso, objF, d, dc
>> > > Dim objWMIService, colFiles, objFile
>> > > Dim FileSizeKB, FileSizeMB, FileSizeGB
>> > >
>> > > Set objWMIService = _
>> > > GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
>> > >
>> > > Set fso = CreateObject("Scripting.FileSystemObject")
>> > >
>> > > Set dc = fso.Drives
>> > >
>> > > For Each d in dc
>> > >
>> > > if d.DriveType = 2 then 'fixed drives only
>> > >
>> > > Set colFiles = objWMIService.ExecQuery("Select * from " & _
>> > > "CIM_DataFile where (Drive='" & d.DriveLetter & ":') " & _
>> > > "and (Extension = 'pst')")
>> > > For Each objFile in colFiles
>> > >
>> > > '1KB = 1024 bytes
>> > > FileSizeKB = objFile.FileSize \ 1024
>> > > '1MB = 1024 * 1024 bytes (1KB * 1024)
>> > > FileSizeMB = objFile.FileSize \ 1024 \ 1024
>> > > '1GB = 1024 * 1024 * 1024 bytes (1MB * 1024)
>> > > FileSizeGB = objFile.FileSize \ 1024 \ 1024 \ 1024
>> > > If FileSizeGB >= 1 Then
>> > > Wscript.Echo objFile.Name & " " & FileSizeGB & " GBytes"
>> > > ElseIf FileSizeMB >= 1 Then
>> > > Wscript.Echo objFile.Name & " " & FileSizeMB & " MBytes"
>> > > ElseIf FileSizeKB >= 1 Then
>> > > Wscript.Echo objFile.Name & " " & FileSizeKB & " KBytes"
>> > > Else
>> > > Wscript.Echo objFile.Name & " " & objFile.FileSize & " Bytes"
>> > > End If
>> > >
>> > > Next
>> > >
>> > > end if
>> > >
>> > > Next
>> > >
>> >
>> >
>> >



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h48.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,27957 seconds with 14 queries