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 - Newbie: Help me OUT

Reply
 
Old 08-26-2006   #1 (permalink)
=?Utf-8?B?S2FseWFu?=


 
 

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 SpecsSystem Spec
Old 08-26-2006   #2 (permalink)
Jeffrey Snover [MSFT]


 
 

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 SpecsSystem Spec
Old 08-27-2006   #3 (permalink)
=?Utf-8?B?S2FseWFu?=


 
 

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 SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Newbie help Gaming
Re: WLM newbie Live Mail
Newbie PowerShell
newbie VB Script
Newbie needs help General Discussion


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