Automation in windows
Hi, I am not sure if i'm in the right group but will ask my question and see if you can help. I would like to download a software or write a script to automatically check the event viewer, disk space, certain processes are running, etc (all in Windows server). Is this possible? I would require this so instead of logging onto 20 or more servers to check these things - it can be done automatically and an email can be sent with certain details. Please keep me posted if this can be done! Thanks
July 4th, 2011 5:13pm

Hi, There are several monitoring softwares that do this indeed...think of SCOM...Otherwise yes you could run a script that connects to each server and reads these details. For this you might best ask in the scripting forum. K
Free Windows Admin Tool Kit Click here and download it now
July 4th, 2011 5:46pm

Ok I will have a look at SCOM. Thanks! If this does most of what I require then no need to script.
July 4th, 2011 6:02pm

Powershell is ideally suited for this kind of work. It's quite a lot of work to get the scripts all working, but it saves a lot of time too! To learn more about Powershell, really quickly, look at Ed Wilson's 5-part video series, here: http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx It's great fun once you get started.
Free Windows Admin Tool Kit Click here and download it now
July 4th, 2011 6:21pm

For example, I have a script that queries Active Directory for all computers in a certain OU, and then gets all the error and warning events for the last 24 hours for each machine in the OU. The script then outputs to a csv file, that I can analyse in Excel. And the whole thing only takes about 2 minutes to run against 30 computers! Imagine doing that manually!
July 5th, 2011 12:25pm

Exactly. I would like to view event viewer, disk space, services/processes. - these i have already found from a powershell tutorial and tested on my pc. However, I would like to run a script that would do this automatically. Next, I would like to run this script from one pc to numerous servers (would be identified via ip addresses?) and return back the data. Any suggestions? ps. servers might be also virtual.
Free Windows Admin Tool Kit Click here and download it now
July 5th, 2011 2:02pm

The 2 cmdlets for getting events, Get-Eventlog and Get-Winevent, both take a -computername parameter, so you can specify multiple computer names in a 'for each' construct. The same applies to Get-Service and Get-WMIObject. For disk space, you need to use WMI, and you can query Win32_LogicalDisk class to get this information. To get a script to run automatically, all you need to do is save it as a .ps1 file. Then, in a .cmd file give the followng command: powershell c:\scripts\myscript.ps1 You need to do it this way because powershell files will not execute from the command line directly. (They will in a Powershell command-line environment).
July 5th, 2011 2:21pm

For example, the following code will run the get-service cmdlet against a list of computers in pc_list.txt: Get-Content -Path pc_list.txt | ForEach-Object { Get-Service -ComputerName $_ } And this will retrieve disk total space and free space information (among other things): Get-WMIObject -Class win32_logicaldisk So, you could do: Get-Content -Path pc_list.txt | ForEach-Object { Get-WMIObject -Class win32_logicaldisk -ComputerName $_ } | Export-CSV -Path diskinfo.csv I think you get the idea!
Free Windows Admin Tool Kit Click here and download it now
July 5th, 2011 7:40pm

Yes. Thanks. Regarding the pc_list ... I am coming across this error when adding other computers: Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESS DENIED)) At line:1 char:63 + Get-Content -Path pc_list.txt | ForEach-Object { Get-WMIObject <<<< -Class w in32_logicaldisk -ComputerName $_ } | Export-CSV -Path diskinfo.csv + CategoryInfo : NotSpecified: (:) [Get-WmiObject], UnauthorizedA ccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.Pow erShell.Commands.GetWmiObjectCommand
July 6th, 2011 8:35am

Hi Lilly, Either you do not have sufficient permissons, or it cannot resolve the pc name. You will have to be a domain admin, or somehow have administrative rights on the pc's you want to query. Trouble-shoot this by simplifying the command to a single pc: gwmi -class win32_logicaldisk -computername TestPC Put your pc name in the list by itself, and see if this works: gc pc_list.txt | % {gwmi -class win32_logicaldisk -cn $_ } (That's the shorthand way of writing it) Also, if you take this to the Scripting Forum, there will be a lot more help available. You can find it here: http://social.technet.microsoft.com/Forums/en-US/ITCG/threads I hope to see you there!
Free Windows Admin Tool Kit Click here and download it now
July 6th, 2011 9:51am

Ok thanks. Yes both work using my pc name. But when I add others I get assess denied. As you said - it's probably a right's issue. I will continue on the other forum! Cheers :)
July 6th, 2011 11:19am

this is my code: Get-Content -Path pc_list.txt | ForEach-Object { Get-WMIObject -Class win32_logicaldisk -ComputerName $_ } | Export-CSV -Path diskinfo.csv Get-Content -Path pc_list.txt | ForEach-Object { Get-EventLog -LogName application -EntryType Warning -ComputerName $_ } | Export-CSV -Path event1info.csv Get-Content -Path pc_list.txt | ForEach-Object { Get-EventLog -LogName system -EntryType Warning -ComputerName $_ }| Export-CSV -Path event2info.csv Get-Content -Path pc_list.txt | ForEach-Object {Get-Service * | where {$_.Status -eq "Stopped"}}| Export-CSV -Path servicesinfo.csv I need to find the disk space, stopped services, and any warnings in the event viewer... At present i am running these 1 by 1 on my pc manually. Now I would like to do the following: 1. Run each command in 1 script 2. Be able to run the script not only on my pc but to other servers and return the data back to my pc 3. Be able to filter certain data... for example the disk space returns a lot of unwanted info - i just want to know - computer name, names of disks, total space avail, free space. For example - services... i would like to just view certain important services - no need to see all the stopped ones 4. Finally, with all this data, I would like to maybe if possible be alerted via email if a particular chosen service stops or disk space is at 80% etc.. I know i wrote loads down but so you can get a clearer picture. Obviously will start step by step :) Any hints/help appreciated!!
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2011 5:17pm

Can anyone help with my query please??
July 11th, 2011 5:39pm

Hi Lilly, I assume the code lines you listed work, and I assume that they work against other computers. (in the pc_list.txt file). If you are having problems getting these lines of code to work, please post to the scripting forum. In my real-world experience, turning the Powershell commands into tools that will produce report-like results is very difficult. They are great for single use purposes, but they don't work well together. I'll explain what I mean: Although, of course, all the scripts will run correctly, and give appropriate output, you cannot easily save all this output from all the scripts into one single 'main' report. For example, you can run the disk space report on a set of computers, and produce a report. But you can't easily run the disk space report and the event report, and expect to get the results in one file. You can, but it will be an untidy, unformatted text file that you could not import into Excel, for instance. Regarding unwanted info returned by your WMI queries, you can filter on properties. Here's a big hint: If you want to know the name of the properties, pipe the output to get-member. e.g. gwmi -class Win32_LogicalDisk | get-member This will list all the properties and methods available to you. You then use the select-object cmdlet to get what you want: gwmi -class Win32_LogicalDisk | Select-Object caption, size, freespace
Free Windows Admin Tool Kit Click here and download it now
July 11th, 2011 7:24pm

And here's another few cent's worth, when it comes to querying WMI: 1. WMI will return infomation in strings or arrays of strings, depending on what you are querying. This makes csv formatting all but impossible. I am thinking here specifically about win32_logicaldisk. 2. To easily see all the WMI classes available to you, and to see all the properties, and the sort of data they return, USE SCRIPTOMATIC VER.2. It's an invaluable tool for WMI scripting, even though it doesn't give you the Powershell code. All due respect to Ed Wilson, but his Scriptomatic just isn't the same. You can get Scriptomatic 2.0 here: http://www.microsoft.com/download/en/details.aspx?DisplayLang=en&id=12028
July 11th, 2011 7:33pm

Yes that's spot on!! Ok i am gonna work on my scripts (one by one) so i get the exact data i need. Any idea on how to run it in a script - no need for multiple queries in one script - just create a .ps1 file as so far i keep getting errors regarding permissions. (so unable to get it to run).
Free Windows Admin Tool Kit Click here and download it now
July 12th, 2011 7:51pm

Scripts are disabled by default in Powershell! To get them to run, you need to open a Powershell console as Administrator (elevated priveliges), and run the following command: set-executionpolicy unrestricted After that, you can run scripts in a normal Powershell window. To actually execute a script from the Powershell prompt, you need to type in the full path name to the ps1 file. If it's in the current directory, you can use: .\runscript.ps1 PS: Remember to marked this question "Answered" at some point ; ) (and some helpful votes wouldn't go unappreciated either!) TIA.
July 12th, 2011 8:05pm

Maybe you can help me with my other query... I have created batch files with my scripts inside - these work and are also scheduled tasks on my pc.. however my next step is running these scripts on other pcs/ servers etc.. 1. do all the other computers need to have powershell installed? 2. can i use my pc as the main server where all scripts are stored and then the other servers can be connected to remotely to get the data? When i want to connect remotely to another server (not via mstsc) but to check the disk space via a command --- how can one connect as so far it keeps asking me to enter the password for a server whilst i would need this to be hardcoded.. thanks!
Free Windows Admin Tool Kit Click here and download it now
July 13th, 2011 4:02pm

1. Yes, they do, unless they are Windows 2008R2 or Windows7. These come with Powershell already installed. However, the down-level machines do not have to have .NET 4 installed on them unless you want to use the Powershell ISE. 2. There may be a security issue with running scripts from a network location. I'm not sure about that one. You'll have to try it out.
July 13th, 2011 4:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics