Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SCCM - Run powershell script as a program

Posted on 2013-10-23
4
Medium Priority
?
1,175 Views
Last Modified: 2013-12-01
Hi,

I really need some help here.

I want to uninstall Lync 2010 and it's MUI pack with SCCM. For that i've made this powershell script:

[String]$File = "C:\Program Files\Microsoft Lync\UcMapi64.exe"
[String]$FileExists = (Test-Path $File -PathType Leaf)
[String]$ShortcutPath_01 = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Lync"
[String]$ShortcutPath_02 = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Vestfrost\Microsoft Lync"
[String]$FilePath = "C:\Program Files (x86)\Microsoft Lync"

if ($FileExists -eq $false)
{
	Exit
}
elseif ($FileExists -eq $true)
{
	#Stopping Lync 2010 from running
	Stop-Process -Name "Communicator"
	
	#Uninstalling Lync 2010
	Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "*Lync*2010*"} | ForEach-Object -process {$_.Uninstall()}
		
	#Deleting shortcuts
	Remove-Item -Path $ShortcutPath_01 -Recurse -Force
	Remove-Item -Path $ShortcutPath_02 -Recurse -Force
    	Remove-Item -Path $FilePath -Recurse -Force
}

Open in new window


I want to run this powershell script as a program from SCCM 2007 R3. I've tried these command so far:

Powershell.exe -ExecutionPolicy Bypass -file "\\Server\Lync\blabla\Uninstall.ps1"
Powershell.exe -ExecutionPolicy Unrestricted -file "\\Server\Lync\blabla\Uninstall.ps1"

All that happens when they run, is that powerhell starts up and then nothing.

I've also tried with a batch script, that copies the powershell-file to the local computer and run it from there, but still nothing happens.

If I run it directly from the file, it Works perfect and removes Lync.

What am I doing wrong? :)
0
Comment
Question by:Sum Wum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39597229
Add the following at the end of the .ps1 file and you can see errors if there are any running the script.


Read-Host "Enter key to Continue"
0
 
LVL 1

Author Comment

by:Sum Wum
ID: 39608591
Nothing happens when I do that.

Now i've created a .bat file that copy the PS1 file to a local drive and run it from there. Nothing happens. But if i run this file that it has just copied to the local pc, from a cmd, it runs just fine.

Does it make any difference that the SCCM client is a 32-bit and the OS is 64-bit, when I execute the powershell-command from SCCM?
0
 
LVL 1

Accepted Solution

by:
Sum Wum earned 0 total points
ID: 39679930
I could not make the powershell script run properbly, so i had to run a batch script instead.

TASKKILL /IM "Communicator.exe" /F
WMIC PRODUCT WHERE IdentifyingNumber="{CEECF731-3F08-4210-8073-7E87F58C01D3}" CALL UNINSTALL
WMIC PRODUCT WHERE IdentifyingNumber="{81BE0B17-563B-45D4-B198-5721E6C665CD}" CALL UNINSTALL
RD "C:\Program Files (x86)\Microsoft Lync" /S /Q
RD "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Lync" /S /Q
EXIT 0

Open in new window

0
 
LVL 1

Author Closing Comment

by:Sum Wum
ID: 39687959
I did get other solutions.
0

Featured Post

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question