![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Newbie: Help me OUT Hi All, I have around 200 computers from which i need to unistall SQL SERVER 2000. My idea is to list the computers in a CSV file, import the CSV into powershell and apply wmi Methods to Uninstall the Software. This is what i want to do, Computer, Status a-b-1, a-b-2, a-b-3, .. .. .. I tried to scribble some script with my limited knowledge and produced the following piece of PS code. $a = Import-Csv c:\sql.csv | $b = $a |foreach { get-WmiObject win32_product -computer $_.computer | select name} $c = $b | where {$_.name -match 'SQL Server'} foreach ($d in $c) { $d.Invokemethod("Uninstall", 1) } I know there are some bugs in this, which i'm trying to resolve. But i dont know how to get the following output Computer, Status a-b-1, Success a-b-2, Failed a-b-3, Errors .. .. .. Not sure how to acheive this, Guess we can reture a value from Uninstall and using the return value i can write success or failure to the CSV, but not sure how to put this to status column of CSV file. Also i want to run this script with admin previledges from a server at scheduled period, Is there any way to embedd credentials encrypted into the script? Guess someone can help me!! Thanks in advance. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Newbie: Help me OUT I'm not going to test this on my machine to see if i got the code correct so there might be errors :-). That is the downside of direct .NET access vs Cmdlet. If it was a Cmdlet, you could just type -WHATIF and things would be great. $list= import-csv c:\sql.csv foreach ($entry in $list) { $prod = Get-WmiObject Win32_Product -computer $a.Computer |where {$_.name -match "SQL Server"} $status = $prod.InvokeMethod("Uninstall",1) switch ($status.ReturnValue) { 0 {$entry.Status = "Success"} 2147549445 {$entry.Status = "RPC Server Fault"} default {$entry.Status = $status.ReturnValue} } } $list |export-csv c:\sql.csv The link below documents the returnValue values: http://msdn.microsoft.com/library/de...32_product.asp -- Jeffrey Snover [MSFT] Windows PowerShell/Aspen Architect Microsoft Corporation This posting is provided "AS IS" with no warranties, no confers rights. Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scr.../hubs/msh.mspx |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Newbie: Help me OUT Thanks, Jeffrey. I'm much delighted to see your reply. I'll try the script in my test domian and put back the results in my next post. "Jeffrey Snover [MSFT]" wrote: > I'm not going to test this on my machine to see if i got the code correct so > there might be errors :-). > That is the downside of direct .NET access vs Cmdlet. If it was a Cmdlet, > you could just type -WHATIF and things would be great. > > $list= import-csv c:\sql.csv > foreach ($entry in $list) > { > $prod = Get-WmiObject Win32_Product -computer $a.Computer |where > {$_.name -match "SQL Server"} > $status = $prod.InvokeMethod("Uninstall",1) > switch ($status.ReturnValue) > { > 0 {$entry.Status = "Success"} > 2147549445 {$entry.Status = "RPC Server Fault"} > default {$entry.Status = $status.ReturnValue} > } > } > $list |export-csv c:\sql.csv > > The link below documents the returnValue values: > http://msdn.microsoft.com/library/de...32_product.asp > -- > Jeffrey Snover [MSFT] > Windows PowerShell/Aspen Architect > Microsoft Corporation > This posting is provided "AS IS" with no warranties, no confers rights. > Visit the Windows PowerShell Team blog at: > http://blogs.msdn.com/PowerShell > Visit the Windows PowerShell ScriptCenter at: > http://www.microsoft.com/technet/scr.../hubs/msh.mspx > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Newbie help | Gaming | |||
| Re: WLM newbie | Live Mail | |||
| Newbie | PowerShell | |||
| newbie | VB Script | |||
| Newbie needs help | General Discussion | |||