Alex
asked on
Sanity check on my powershell script please
OK,
So this PowerShell script is meant to do the following
Does that look right? Before you ask, yes I've tested it but I see no issue getting someone else to check it over :-)
Thanks
Alex
So this PowerShell script is meant to do the following
- Pull the list of computers
- Connect to the machine and check if it's C$ or support$
- Copy the TillSC folder which contains PSexec etc
- Execute the .com file which runs the SC command to delete a service
- Report it back if it's not online.
$Computers = Get-content "C:\Powershell Projects\TillSC\computers.txt"
$source = "C:\Powershell Projects\TillSC"
foreach ($computer in $computers) {
$X = gwmi win32_share -ComputerName $computer | Where-Object {$_.Name -eq "Support$"}
if($X.Name -eq 'Support$')
{
$dest = "Support$\Temp"
}
else
{
$dest = "C$\Temp"
}
Copy-Item $source -Destination \\$computer\$dest -Recurse -Force
}
foreach ($computer in $computers) {
if (test-Connection -Cn $computer -quiet) {
C:\Powershell Projects\Tills\PSexec.exe -d -s "\\$computer" "C:\Temp\TillSC\SCDelete.com"
} else {
"$computer is not online" | Out-file -Append "C:\Powershell Projects\TillSCcomputersnotonline.txt"
}
}
Does that look right? Before you ask, yes I've tested it but I see no issue getting someone else to check it over :-)
Thanks
Alex
ASKER
Because I can't execute the SC command through PSexec for some reason.
Plus, well that's it, Btw, the .com file contains the following
SC delete WinVNC4, so technically I'm using SC I just put it in a .com batch file :(
Plus, well that's it, Btw, the .com file contains the following
SC delete WinVNC4, so technically I'm using SC I just put it in a .com batch file :(
You cannot have checked your script, because the psexec call uses an unquoted path containing spaces ...
SC can run directly against remote. No psexec required!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, cool :-)
Thanks for that, I'll give it a shot :-)
Thanks for that, I'll give it a shot :-)
Then I have a question: why are you using two external programs (one of them being a .com, which AV software rightfully frowns upon these days) for something that sc.exe supports natively? sc.exe can remove services remotely as well.
Open in new window