Deploy powershell script - Uninstall Forefront

Hi
Im trying to build a powershell script that uninstall Forefront Client and later install SCEP and it also copy the local exclusions from Forefront to insert in SCEP (registry).
All works fine when Im running the script locally, but when Im deploying it from Altiris DS it halts on Microsoft Forefront Client Security Antimalware Service". Every time, I also have tried to sort them differently but it wont work.
All I see in the event viewer is a warning:
"Application 'C:\Program Files\Microsoft Forefront\Client Security\Client\Antimalware\MSASCui.exe' (pid 1964) cannot be restarted - Application SID does not match Conductor SID.."
And then later an error:
HRESULT:0x80070643
Description:Cannot complete the System Center Endpoint Protection installation. An error has prevented the System Center Endpoint Protection setup wizard from completing successfully. Please restart your computer and try again. Error code:0x80070643. Fatal
error during installation.
This is the deployment from Altiris:
powershell.exe -noexit "& 'C:\Temp\ForefrontSCEP.ps1'"
Does anyone has any clue?
Cheers!
**** The script ****
# Backup Forefront registry data
Reg export "HKLM\SOFTWARE\Microsoft\Microsoft Forefront" C:\Temp\SCEPClient_New\exclbackup.reg
# Create new registry item
new-Item "HKLM:\SOFTWARE\Microsoft\" -Name "Microsoft Antimalware"
new-Item "HKLM:\SOFTWARE\Microsoft\Microsoft Antimalware\" -Name Exclusions
# Copy Forefront registry exclusion data to newly created regkey
Copy-Item "HKLM:\SOFTWARE\Microsoft\Microsoft Forefront\Client Security\1.0\AM\Exclusions" -Destination "HKLM:\SOFTWARE\Microsoft\Microsoft Antimalware\" -Recurs
# "Uninstall Forefront och MOM"
# "Uninstall Microsoft MOM"
$app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match "Microsoft Operations Manager 2005 Agent"
$app.Uninstall()
# "Uninstall Forefront Assessment"
$app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match "Microsoft Forefront Client Security State Assessment Service"
$app.Uninstall()
# "Uninstall Forefront Antimalware"
$app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match "Microsoft Forefront Client Security Antimalware Service"
$app.Uninstall()
# Install SCEP with policy
Start-Process -FilePath C:\Temp\SCEPClient_New\scepinstall.exe -ArgumentList "/s /q /policy C:\Temp\SCEPClient_New\ServerSCEP.xml" -ErrorAction SilentlyContinue

I finally solved, in two ways.
For the powershell part:
I changed the name match against a filter function. So now I can deploy the powershell script just fine.
$app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match "Microsoft Operations Manager 2005 Agent"
$application = Get-WMIObject Win32_Product -filter "Name='Microsoft Operations Manager 2005 Agent'"
2nd solution:
I also created a batch file which worked at my first try. Gotta love the old fashion way :)
I post it here as well, maybe somebody can get use of it.
Uninstall Forefront - Install SCEP - Copy local exclusions
REM Backup Forefront exclusions
regedit /e C:\Temp\ForefrontExclBackup.reg "HKLM\Software\Microsoft\Microsoft Forefront"
REM Create SCEP registry keys
reg add "HKLM\Software\Microsoft\Microsoft Antimalware"
REM Create SCEP registry keys
reg add "HKLM\Software\Microsoft\Microsoft Antimalware\Exclusions"
REM Copy Foreront exclusions to SCEP
reg copy "HKLM\Software\Microsoft\Microsoft Forefront\Client Security\1.0\AM\Exclusions" "HKLM\Software\Microsoft\Microsoft Antimalware\Exclusions" /s /f
REM Uninstall Microsoft Forefront Client Security State Assessment Service
MsiExec.exe /X{E8B56B39-A826-11DB-8C83-0011430C73A4} /qn
REM Uninstall Microsoft Forefront Client Security Antimalware Service
MsiExec.exe /X{436028CD-6476-4224-9274-8F0320F30FD1} /qn
REM Uninstall Microsoft Operations Manager 2005 Agent
MsiExec.exe /X{F692770D-0E27-4D3F-8386-F04C6F434040} /qn
REM Install SCEP and policys
C:\Temp\SCEPInstall.exe /policy C:\Temp\ServerSCEP.xml /s

Similar Messages

  • Deploy Powershell Script As An Application Install Question

    I want to create an application (not packages) to run a powershell script to install a software. In this script it installs software and copies files over to different directories. Is there a way to do this in Applications? Currently I've been creating
    task sequences to accomplish this which does work but I was wondering if this could be done thru applications or maybe if there is some better idea of doing this. Any advice would be grateful. Thanks in advance.

    Hi,
    Any updates?
    If this problem has not been resolved, please check AppIntentEval.log and AppEnforce.log to see whether there are some helpful information.  
    " I can run it manually from the ccmcache folder and it'll install the software but when running the "install.ps1" file from SCCM it doesn't install the software but does copy files to the directory specified."
    Could this be related to the account running the script? How about running as system account?
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Trying to deploy a batch or powershell script unsuccessful

    I've deployed a .cmd file out that contains a WMI script to uninstall all instances of an application called "VirtViewer". The script looks like this:
    taskkill /F /IM remote-viewer.exe /T
    wmic product where "name like 'VirtViewer%%'" call uninstall /nointeractive
    exit /B %EXIT_CODE%
    Previously, I had used MSI product codes for the uninstall, and got the same result. My original problem, is that there are currently 9 different versions of this app out there, so i am ripping them all out and replacing with 1 version. Installing over an
    old version does not overwrite the older one, it instead installs a new instance.
    Reading through the execmgr.log on the client, everything looks as it should.
    The end result, is that nothing happens. I had originally set the program to run as hidden, but then changed it to normal but still do not see it run. The application is right where i left it, untouched. If i run the script locally it works fine, but not
    when deployed. Am i missing something??
    <![LOG[Service startup.]LOG]!><time="16:09:31.647+300" date="01-12-2015" component="execmgr" context="" type="1" thread="248" file="execmgr.cpp:135">
    <![LOG[A user has logged on.]LOG]!><time="16:09:43.507+300" date="01-12-2015" component="execmgr" context="" type="1" thread="4256" file="execreqmgr.cpp:4911">
    <![LOG[Requesting content from CAS for package VNT00018 version 21]LOG]!><time="16:11:13.649+300" date="01-12-2015" component="execmgr" context="" type="1" thread="124" file="contentaccesshelper.cpp:246">
    <![LOG[Policy arrived for parent package VNT00018 program Uninstall Script]LOG]!><time="16:11:13.649+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2528" file="execreqmgr.cpp:6893">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 6l, value NULL, user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:13.665+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2528" file="event.cpp:405">
    <![LOG[Successfully created a content request handle {B2BA42EE-5988-47F4-BF44-ADAAC975994B} for the package VNT00018 version 21]LOG]!><time="16:11:13.665+300" date="01-12-2015" component="execmgr" context="" type="1" thread="124" file="contentaccesshelper.cpp:331">
    <![LOG[Program Uninstall Script change to state STATE_ADVANCED_DOWNLOAD content available]LOG]!><time="16:11:13.665+300" date="01-12-2015" component="execmgr" context="" type="2" thread="124" file="executionrequest.cpp:3663">
    <![LOG[Execution Request for advert VNT20014 package VNT00018 program Uninstall Script state change from NotExist to AdvancedDownload]LOG]!><time="16:11:13.665+300" date="01-12-2015" component="execmgr" context="" type="1" thread="124" file="executionrequest.cpp:501">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:13.665+300" date="01-12-2015" component="execmgr" context="" type="1" thread="124" file="event.cpp:405">
    <![LOG[Raising event:
    [SMS_CodePage(437), SMS_LocaleID(1033)]
    instance of SoftDistProgramOfferReceivedEvent
    AdvertisementId = "VNT20014";
    ClientID = "GUID:E306FF26-C884-4E36-9C03-C19523A17F40";
    DateTime = "20150112211113.665000+000";
    MachineName = "VM-WIN7-MIKE";
    ProcessID = 1788;
    SiteCode = "VNT";
    ThreadID = 2528;
    ]LOG]!><time="16:11:13.665+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2528" file="event.cpp:715">
    <![LOG[Mandatory execution requested for program Uninstall Script and advertisement VNT20014]LOG]!><time="16:11:13.680+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="execreqmgr.cpp:3527">
    <![LOG[Creating mandatory request for advert VNT20014, program Uninstall Script, package VNT00018]LOG]!><time="16:11:13.680+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="execreqmgr.cpp:3653">
    <![LOG[An existing MTC token was not supplied, using ExecutionRequest's Id as MTC token and this execution request is the owner of resultant MTC task.]LOG]!><time="16:11:13.696+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="executionrequest.cpp:8942">
    <![LOG[Request a MTC task for execution request of package VNT00018, program Uninstall Script with request id: {D52026A7-5735-402B-868C-EF9791656512}]LOG]!><time="16:11:13.696+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="executionrequest.cpp:8966">
    <![LOG[Execution Request for advert VNT20014 package VNT00018 program Uninstall Script state change from WaitingDependency to Ready]LOG]!><time="16:11:13.712+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="executionrequest.cpp:501">
    <![LOG[MTC task with id {D52026A7-5735-402B-868C-EF9791656512}, changed state from 0 to 4]LOG]!><time="16:11:13.712+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="execreqmgr.cpp:6288">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:13.712+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="event.cpp:405">
    <![LOG[MTC signaled SWD execution request with program id: Uninstall Script, package id: VNT00018 for execution.]LOG]!><time="16:11:13.743+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="execreqmgr.cpp:6406">
    <![LOG[Sending ack to MTC for task with id: {D52026A7-5735-402B-868C-EF9791656512}]LOG]!><time="16:11:13.743+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="executionrequest.cpp:9005">
    <![LOG[Executing program VirtViewerUninstall.cmd in Admin context]LOG]!><time="16:11:13.743+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="executionrequest.cpp:3239">
    <![LOG[Execution Request for advert VNT20014 package VNT00018 program Uninstall Script state change from Ready to NotifyExecution]LOG]!><time="16:11:13.743+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="executionrequest.cpp:501">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:13.759+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="event.cpp:405">
    <![LOG[Checking content location C:\Windows\ccmcache\1c for use]LOG]!><time="16:11:13.774+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="executioncontext.cpp:1663">
    <![LOG[Successfully selected content location C:\Windows\ccmcache\1c]LOG]!><time="16:11:13.774+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="executioncontext.cpp:1719">
    <![LOG[Executing program as a script]LOG]!><time="16:11:13.774+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="executionengine.cpp:82">
    <![LOG[Successfully prepared command line "C:\Windows\ccmcache\1c\VirtViewerUninstall.cmd"]LOG]!><time="16:11:13.774+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="scriptexecution.cpp:650">
    <![LOG[Command line = "C:\Windows\ccmcache\1c\VirtViewerUninstall.cmd", Working Directory = C:\Windows\ccmcache\1c\]LOG]!><time="16:11:13.774+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="scriptexecution.cpp:352">
    <![LOG[Running "C:\Windows\ccmcache\1c\VirtViewerUninstall.cmd" with 32bitLauncher]LOG]!><time="16:11:13.774+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="scriptexecution.cpp:370">
    <![LOG[Created Process for the passed command line]LOG]!><time="16:11:13.852+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="scriptexecution.cpp:513">
    <![LOG[Raising event:
    [SMS_CodePage(437), SMS_LocaleID(1033)]
    instance of SoftDistProgramStartedEvent
    AdvertisementId = "VNT20014";
    ClientID = "GUID:E306FF26-C884-4E36-9C03-C19523A17F40";
    CommandLine = "\"C:\\Windows\\ccmcache\\1c\\VirtViewerUninstall.cmd\"";
    DateTime = "20150112211113.852000+000";
    MachineName = "VM-WIN7-MIKE";
    PackageName = "VNT00018";
    ProcessID = 1788;
    ProgramName = "Uninstall Script";
    SiteCode = "VNT";
    ThreadID = 2164;
    UserContext = "NT AUTHORITY\\SYSTEM";
    WorkingDirectory = "C:\\Windows\\ccmcache\\1c\\";
    ]LOG]!><time="16:11:13.852+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="event.cpp:715">
    <![LOG[Raised Program Started Event for Ad:VNT20014, Package:VNT00018, Program: Uninstall Script]LOG]!><time="16:11:13.852+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="executioncontext.cpp:459">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 1l, value NULL, user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:13.852+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="event.cpp:405">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:13.868+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="event.cpp:405">
    <![LOG[MTC task with id {D52026A7-5735-402B-868C-EF9791656512}, changed state from 4 to 5]LOG]!><time="16:11:13.884+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2164" file="execreqmgr.cpp:6288">
    <![LOG[Program exit code 0]LOG]!><time="16:11:17.571+300" date="01-12-2015" component="execmgr" context="" type="1" thread="4128" file="scriptexecution.cpp:676">
    <![LOG[Looking for MIF file to get program status]LOG]!><time="16:11:17.571+300" date="01-12-2015" component="execmgr" context="" type="1" thread="4128" file="executionstatus.cpp:282">
    <![LOG[Script for Package:VNT00018, Program: Uninstall Script succeeded with exit code 0]LOG]!><time="16:11:17.571+300" date="01-12-2015" component="execmgr" context="" type="1" thread="4128" file="executionstatus.cpp:262">
    <![LOG[Raising event:
    [SMS_CodePage(437), SMS_LocaleID(1033)]
    instance of SoftDistProgramCompletedSuccessfullyEvent
    AdvertisementId = "VNT20014";
    ClientID = "GUID:E306FF26-C884-4E36-9C03-C19523A17F40";
    DateTime = "20150112211117.571000+000";
    MachineName = "VM-WIN7-MIKE";
    PackageName = "VNT00018";
    ProcessID = 1788;
    ProgramName = "Uninstall Script";
    SiteCode = "VNT";
    ThreadID = 4128;
    UserContext = "NT AUTHORITY\\SYSTEM";
    ]LOG]!><time="16:11:17.587+300" date="01-12-2015" component="execmgr" context="" type="1" thread="4128" file="event.cpp:715">
    <![LOG[Raised Program Success Event for Ad:VNT20014, Package:VNT00018, Program: Uninstall Script]LOG]!><time="16:11:17.587+300" date="01-12-2015" component="execmgr" context="" type="1" thread="4128" file="executioncontext.cpp:483">
    <![LOG[Execution is complete for program Uninstall Script. The exit code is 0, the execution status is Success]LOG]!><time="16:11:17.587+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="execreqmgr.cpp:4165">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 10l, value Result:TRUE ,SDKCallerId:, user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:17.602+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="event.cpp:405">
    <![LOG[Requesting MTC to delete task with id: {D52026A7-5735-402B-868C-EF9791656512}]LOG]!><time="16:11:17.618+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="executionrequest.cpp:9036">
    <![LOG[MTC task with id: {D52026A7-5735-402B-868C-EF9791656512} deleted successfully.]LOG]!><time="16:11:17.618+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="executionrequest.cpp:9065">
    <![LOG[Raising client SDK event for class CCM_Program, instance CCM_Program.PackageID="VNT00018",ProgramID="Uninstall Script", actionType 1l, value , user NULL, session 4294967295l, level 0l, verbosity 30l]LOG]!><time="16:11:17.618+300" date="01-12-2015" component="execmgr" context="" type="1" thread="2564" file="event.cpp:405">

    I just tried using powershell to accomplish the same task, and got the same result. Script ran fine, but nothing resulted. 0 errors in the execmgr.log on the client.
    Program options:
    Command Line: Powershell.exe -executionpolicy Bypass -file .\VirtUninstall.ps1
    the powershell script looks like this:
    $app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match "VirtViewer*"}
    $app.Uninstall()
    exit /B
    Again, the script runs great when launched locally, but not wehen deployed

  • PowerShell Script to get the details Like Scope,Last Deployed date and Name for a Solution Deployed in the Farm.

    Hi Experts,
    I am trying to  build a PowerShell Script to get the details Like Scope,Last Deployed date and Name for a Solution Deployed in the Farm.
    Can anyone advise on this please.
    Regards

    Get-SPSolution|Select Name,Scope,LastOperationResult,LastOperationEndTime|Export-CSV "SPInstalledSolutions.csv" -NoTypeInformation
    SPSolution properties
    Get-SPSolution
    This post is my own opinion and does not necessarily reflect the opinion or view of Slalom.

  • Application deployment evaluation powershell script

    Hi,
    Is there a way that I can run a powershell script or vbs script that will allow me to run the Client actions on the local client. kind of like a shortcut that will go into the configuration manager client control panel icon and run the client action required.
    Specifically for the Application Deployment Evaluation
    Any help would be appreciated
    Regards
    Mike

    Hi,
    Check out this old thread on the topic,
    http://social.technet.microsoft.com/Forums/en-US/9ec7318f-4ab7-4db3-bfa5-958ab1c39f4f/application-deployment-evaluation-cycle-not-willing-to-start-by-script?forum=configmanagersdk
    An example is included in there as well.
    You can also use the Right-click tools extensions in the console which include this action as well.
    http://myitforum.com/myitforumwp/2012/09/21/sccm-rctools/
    Regards,
    Jörgen
    -- My System Center blog ccmexec.com -- Twitter
    @ccmexec

  • Powershell scripting multiple WSP deployment

    I'm moving an application with around 40 custom WSPs to a new environment, and need to find a way to script their deployment. Around half of them are Globally deployed.
    I can deploy them one at a time using
    add-spsolution –literalpath c:\...\SolutionName.wsp
    Check _admin/solutions.aspx to ensure it's in Solution Management
    Select wsp and Deploy Solution
    Go to application
    Site Actions > Site Settings > Site Collection Administration > Site Collection Features
    Activate new feature
    Can anyone point out documentation on how to do this in an automated fashion? 
    Thanks,
    Scott

    Hi Scott,
    Powershell script for deploying multiple solution
    http://deploymentpowershell.codeplex.com/
    http://gallery.technet.microsoft.com/projectserver/Deploy-multiple-wsp-file-1114692f
    and this thread as simplified version
    http://social.technet.microsoft.com/Forums/en-US/72771456-5e6e-4910-b586-a4450ac61c3d/how-to-deploy-multiple-wsp-solutions-in-the-farm-or-same-server?forum=sharepointadminprevious
    You can check this site to learn PowerShell
    http://technet.microsoft.com/en-us/sharepoint/jj672838.aspx
    http://sergeluca.wordpress.com/2011/09/07/my-sharepoint-2010-powershell-tutorial-for-sharepoint-200-developers/
    http://www.youtube.com/watch?v=UuLho-HecXA
    there are good books on PowerShell
    PowerShell for SharePoint 2013 how to
    Beginning PowerShell for SharePoint 2013
    see this blog for more information
    http://www.matthewjbailey.com/sharepoint-powershell-programming-learning/
    Hope this helps!
    Ram - SharePoint Architect
    Blog - SharePointDeveloper.in
    Please vote or mark your question answered, if my reply helps you

  • Does Forefront Endpoint Protection 2010 block powershell scripts from running?

    Hi all,
    I have a task that runs a Powershell script on a set schedule on a particular machine.  It has failed to run and I thought 1 of the potential reasons would be that FEP 2010 blocks the Powershell script from being run.  Does FEP 2010 do that?  If so, where can I find the setting to allow Powershell scripts (or VB scripts or Java scripts) to be run by my task?
    Thanks for your help in advance.
    Howard Lee - Microsoft

    If the script detect as malicious , FEP will block it, otherwise it won't block normal and safe PowerShell scripts. You may take a look at event viewer and see whether it being blocked or detect as malicious code by FEP or not.

  • Error while adding the app in the sharepoint(2013) page through powershell script

    Hi,
        I have created one powershell script to uninstall and install the sharepoint 2013 apps. The code is working fine, but after adding the app in the page I am getting the error "
    Internet Explorer can not display the webpage".
    If I am deploying the app through Visual Studio, its getting deployed successfully and I am getting an option to trust the app.And I am able to add it in the page. But this permission is not coming when I am installing the app using power shell.
    Please let me know whether to do any modifications to the power shell script.
    Thanks.
    Pradeep

    Hi,
       We are using sharepoint hosted app.
    Below is the script to uninstall and install the app.
    cls
    Add-PSSnapin Microsoft.SharePoint.PowerShell –ea SilentlyContinue
    # uninstall the app
    Write-Host "uninstallation of app"
    $InstalledSPApps = Get-SPAppInstance -Web "http://mySharepointSite.xyz.com"
    $appToUninstall = $InstalledSPApps | where {$_.Title -eq 'myCustomSharepointApp'}
    if ($appToUninstall -ne $null)
        Uninstall-SPAppInstance -Identity $appToUninstall ;
        Write-Host "uninstalled successfully"
    # Import-SPAppPackage
    Write-Host "Import the app"
    pause
    $sourceApp = ([microsoft.sharepoint.administration.spappsource]::RemoteObjectModel);
    $myspapp = Import-SPAppPackage -Path "D:\SharePoint 2013\AppsSolution\myCustomSharepointApp.app" -Site "http://mySharepointSite.xyz.com" -Source $sourceApp ;
    Write-Host "Enter to install the app"
    pause
    $app = Install-SPApp -Web "http://mySharepointSite.xyz.com" -Identity $myspapp;
    $AppName = $app.Title;
    Write-Host "app '$AppName' registered"
    pause
    $appInstance = Get-SPAppInstance -Web "http://mySharepointSite.xyz.com" | where-object {$_.Title -eq $AppName};
    $counter = 1;
    $maximum = 150;
    $sleeptime = 2;
    Write-Host -ForegroundColor White "Please wait..." -NoNewline;
    pause
    while (($appInstance.Status -eq ([Microsoft.SharePoint.Administration.SPAppInstanceStatus]::Installing)) -and ($counter -lt $maximum))
        Write-Host "." -NoNewline;
        sleep $sleeptime;
        $counter++;
        $appInstance = Get-SPAppInstance -Web "http://mySharepointSite.xyz.com" | where-object {$_.Title -eq $AppName}
    pause
    if ($appInstance.Status -eq [Microsoft.SharePoint.Administration.SPAppInstanceStatus]::Installed)
        Write-Host "The App was successfully installed.";
        $appUrl = $appInstance.AppWebFullUrl;
        Write-Host -ForegroundColor White "The App is available at '$appUrl'.";

  • PowerShell script to Retract & Remove all farm solutions

    Hi,
    I need the PowerShell script to Retract & Remove all SharePoint farm solutions.
    Single solution Retract & Remove
    Uninstall-SPSolution -Identity <Solution name.wsp>
    ex: Uninstall-SPSolution -Identity Solution.wsp
    Remove-SPSolution -Identity <Solution name.wsp>
    ex: Remove-SPSolution -Identity Solution.wsp

    Install & Uninstall solutions from folder
    file name - installwsp.ps1
    Add-PsSnapin Microsoft.SharePoint.PowerShell
    #Do not modify anything in the script from here onwards
    function Get-ScriptDirectory
    $Invocation = (Get-Variable MyInvocation -Scope 1).Value
    Split-Path $Invocation.MyCommand.Path
    function Deploy-Solution{
    param(
    [string]$physicalPath,
    [string]$name)
    $SolutionName = $name
    $SolutionPath = Join-Path ($physicalPath) $SolutionName
    echo "Extracting information from $physicalPath"
    #Admin service
    $AdminServiceName = "SPAdminV4"
    $IsAdminServiceWasRunning = $true;
    if ($(Get-Service $AdminServiceName).Status -eq "Stopped")
    $IsAdminServiceWasRunning = $false;
    Start-Service $AdminServiceName
    Write-Host 'SERVICE WAS STOPPED, SO IT IS NOW STARTED'
    #Uninstall
    Write-Host 'UNINSTALLING SOLUTION ...'
    $Solution = Get-SPSolution | ? {($_.Name -eq $SolutionName) -and ($_.Deployed -eq $true)}
    if ($Solution -ne $null)
    if($Solution.ContainsWebApplicationResource)
    Uninstall-SPSolution $SolutionName -AllWebApplications -Confirm:$false
    else
    Uninstall-SPSolution $SolutionName -Confirm:$false
    while ($Solution.JobExists)
    Start-Sleep 2
    Write-Host 'SOLUTION HAS BEEN UNINSTALLED SUCCESSFULLY.'
    Write-Host 'REMOVING SOLUTION ...'
    if ($(Get-SPSolution | ? {$_.Name -eq $SolutionName}).Deployed -eq $false)
    Remove-SPSolution $SolutionName -Confirm:$false
    Write-Host 'SOLUTION HAS BEEN REMOVED SUCCESSFULLY.'
    Write-Host 'ADDING SOLUTION ...'
    Add-SPSolution $SolutionPath | Out-Null
    Write-Host 'SOLUTION HAS BEEN ADDED SUCCESSFULLY.'
    Write-Host 'DEPLOYING SOLUTION ...'
    $Solution = Get-SPSolution | ? {($_.Name -eq $SolutionName) -and ($_.Deployed -eq $false)}
    #use '-force' paramater to install all commands in this if statement
    if(($Solution -ne $null) -and ($Solution.ContainsWebApplicationResource))
    Install-SPSolution $SolutionName –AllwebApplications -GACDeployment -Force -Confirm:$false
    else
    Install-SPSolution $SolutionName -GACDeployment -Force -Confirm:$false
    while ($Solution.Deployed -eq $false)
    Start-Sleep 2
    Write-Host 'SOLUTION HAS BEEN DEPLOYED SUCCESSFULLY.'
    if (-not $IsAdminServiceWasRunning)
    Stop-Service $AdminServiceName
    #Get Current Physical Path
    $currentPhysicalPath = Get-ScriptDirectory
    #Iterate through all .wsp files in the current Physical Path to deploy solution
    get-childitem $currentPhysicalPath -include *.wsp -recurse | foreach ($_) {Deploy-Solution $currentPhysicalPath $_.name}
    #Remove SharePoint Snapin
    Remove-PsSnapin Microsoft.SharePoint.PowerShell
    Echo Finish
    Usage file name - installwsp.bat
    cd /c %~dp0
    powershell -noexit -file "installwsp.ps1" "%CD%"
    pause
    Anandhan.S Remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

  • I have a infopath form and i want to publish this form using powershell script(No central admin usage) and i am using Infopath 2010.

    How to publish infopath form using powershell script in infopath 2010?
    Is any approach for such solution.

    Hi,
    Try below command:
    Uninstall the existing solution (based on the from file name):
    Uninstall-SPInfoPathFormTemplate -Identity Exampleform.xsn
    Install the new solution (based on the from file name):
    Install-SPInfoPathFormTemplate -Path C:\Form.xsn
    Disable feature on site collection level
    Disable-SPInfoPathFormTemplate -Identity "Form.xsn" -Site http://SPSite
    Enable feature on site collection level
    Enable-SPInfoPathFormTemplate -Identity "Form.xsn" -Site "http://SPSite"
    See this blogs for your ref:
    http://rgielen.blogspot.in/2010/11/deploy-infopath-2010-forms-with.html
    http://mysharepointwork.blogspot.in/2010/09/deploy-infopath-forms-with-powershell.html
    Hope it could help
    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"
    Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever
    you see a reply being an answer to the question of the thread, click "Mark As Answer

  • Using Echo Command in PowerShell Script for Configuration Item

    Hello All,
    Before you tell me to post my PowerShell question to the PowerShell Forum, please know that the PowerShell portion of my task works just fine. It is the SCCM portion of my task that keeps failing, so that is why I am here. To give some background...
    There are two servers in our SCCM test environment. Both the SCCM server and SQL DB server are 2012, patched and updated.
    Test servers in my Device Collection being used for running Baselines and Reports against are 2008R2 and 2012, patched and updated.
    I have created a Configuration Item that checks to see if the FTP Server Role Feature has been installed on a 2008 or 2012 server. To do the check, I am using the following PowerShell script:
    (get-windowsfeature -Name Web-Ftp-Server).Installed
    When I log into my 2008R2 and 2012 test servers, and run this command directly on the server, it will return a "True" if the FTP Server Role Feature is installed on either server, and a "False" if it is not installed. Basically,
    it works as advertised.
    When I setup my Configuration Item and then deploy my Baseline, or run a report against my device collection of test servers, SCCM will return a correct response (True or False) for the 2012 test server, but throws the following error for the 2008R2
    server:
    0x87df00329 application requirement evaluation or detection failed
    Google searches for this have not been very helpful.
    Now, when I created the Configuration Item and referenced PowerShell, the configuration screen has the following note:
    "Specify the script to find and return the value to be assessed for compliance on client devices. Use the echo command to return the script value to Configuration Manager."
    Since I did not include an echo command in my PowerShell script above, I figured that was my problem, so I did the following:
    Logging onto both of my test servers (2008R2 & 2012) I was able to successfully run the following PowerShell commands and get the expected responses of True or False:
    (get-windowsfeature -Name Web-Ftp-Server).Installed | echo
    (get-windowsfeature -Name Web-Ftp-Server).Installed | write-output (http://technet.microsoft.com/en-us/library/hh849921.aspx)
    (get-windowsfeature -Name Web-Ftp-Server).Installed | write-host (http://technet.microsoft.com/en-us/library/ee177031.aspx)
    However, when I use any of these PowerShell commands in my Configuration Item, NEITHER of my test servers returns a response to the SCCM server.
    When I check the report, both servers show as "Unknown" and when I click on the number 2 (as in 2 servers unknown), the following report page (List of unknown assets for a configuration baseline) has absolutely no data/information at all.
    So...I am at a loss.
    SCCM tells me to use an echo command to return a script value to Configuration Manager. The PowerShell scripts above, with the various echo related commands, work just fine on the servers themselves, but they return no information when run via SCCM.
    What am I missing?
    Any help will be appreciated.
    Thanks in advance for your time.

    Sorry for my ignorance, but I don't understand. (I forgot to mention that I am new at both PowerShell and SCCM.)
    After I change the PowerShell script to add the echo/write-output/write-host cmdlet, I open the ConFig Item and "Clear" the PowerShell script and then re-add it. When I do that, it correctly shows the change in the ConFig Item.
    Next I open the Baseline, then open the ConFig Item within the Baseline to make sure the change is reflected there as well, which it is.
    I then deploy the Baseline to my Device Collection. After that, I run a report against the Baseline and Device Collection and it returns the "Unknown" result.
    If I open the PowerShell script and remove the echo/write-output/write-host cmdlet, then go through the rest of the process of updating and reporting, the result it returns changes, showing one server in compliance and the other server out of compliance,
    which leads me to think that all changes have taken correctly.
    Does that sound right? If I manually deploy the Baseline, is that the same as the client retrieving policies from the management point?
    Sorry to be so thick but I'm learning as I go.
    Thanks again for your help.

  • How to change maintenance powershell script via GPO?

    Per suggestion reposted from here: http://social.technet.microsoft.com/Forums/windowsserver/en-US/6eece9d6-a524-48aa-8e64-7554f0ec9b31/how-to-change-maintenance-powershell-script-via-gpo?forum=winserverGP
    Posted at http://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/desktop-shortcuts-to-items-on-network-drives/94eddb27-342b-40fc-9ad4-677ff4ee8ebe?page=9&tm=1403700614489 originally.
    There is a very annoying "feature" in Windows 7 called BrokenShortcuts.ps1 which is being called out weekly via maintenance task and if it finds more than 4 "broken" network shortcuts it removes them all. So it means if a user at this
    moment is disconnected from the network he will lose all links to shares, network applications sitting on his desktop. Funny that there was no such script on Vista and i don't see this on Win8. On the post i have attached one user suggested to edit this script
    and change 4 to 500 or whatever high number. That's fine for one time fix. But i need to do this for 200+ users. This file cannot be simply replaced by a script, so i'm wondering is there any way to do it via GPO?
    I have already tried various startup scripts, but i'm not sure which user to put into commands.
    I need to run this on startup:
    takeown /F C:\Windows\diagnostics\scheduled\Maintenance\TS_BrokenShortcuts.ps1
    icacls c:\windows\diagnostics\scheduled\maintenance\TS_BrokenShortcuts.ps1 /grant "some user":F
    copy \\share\folder$\TS_BrokenShortcuts.ps1 C:\Windows\diagnostics\scheduled\Maintenance\ /Y

    You need to take time to study how Windows does these things.  You can control them with GP which is what you asked.  The article shows you how to disable elements of the tasks.  Each task controls a script.  If you disable the task the
    script that deletes shortcuts will be stopped. Other maintenance tasks will continue to run.
    Most of your problem is that you seem to want someone to provide a magical solution.  In technology it is necessary to fully research your issues until you understand all aspects.  After fully studying the issue you should understand the possible
    solutions if they exist.
    You claim to have deployed the patch that Microsoft released to fix the issue.  You claim it didn't work.  If that is the case then you need to call MS and \p[en a support incident.  If  Microsoft determines that you are right about the
    patch not working you will not be charged for the call.
    I know that learning how to support technology is hard and frustrating for newcomers.  In time, by using these incidents to learn, you will become a seasoned technician and all of this will seem trivial.  Until then we can only suggest that you
    do things that most of us are familiar with.  We cannot fix your network for you.
    I think you haven't really posted in the GP forum but posted a question about GP in the server forum.  Try posting in the GP forum.
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverGP
    Here is one answer from the GP forum:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverGP
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/600ca14f-8b1b-400c-b27f-a7f5733407ac/windows-scheduled-maintenance-task?forum=winserverGP
    ¯\_(ツ)_/¯

  • FIM Reporting ETLScript PowerShell Script for SCSM 2012?

    Hi,
    The FIM Reporting Deployment Guide is great, however on a few occasions it forgets to mention where you meant to execute things (http://technet.microsoft.com/en-us/library/jj133855(v=ws.10).aspx) .
    For example, if it wasn't for the screenshot in the article, we would not have known that we need to run the ETLScript from the FIM Service/Portal server.
    Everything until the ETLScript has thus far worked; and we have deployed the Service Manager 2012 console on the FIM Service/Portal server (since we are using SCSM 2012 for FIM Reporting).
    However, it appears that the ETLScript (in the deployment guide) has been written for SCSM 2010.
    So, has Microsoft or anyone published an updated SCSM 2012 ETLScript script?
    Thanks,
    SK

    Could this be it?
    http://gallery.technet.microsoft.com/PowerShell-Script-to-Run-a4a2081c

  • Passing parameters with spaces to SCCM Run PowerShell Script task

    I am working on an OS deployment task sequence in SCCM 2012 R2 with several Run PowerShell Script tasks.  Most of them run fine, but I am having trouble with the one I need to pass parameters to.
    The parameters I need to pass are:
    -ComputerOU "ou=All Workstations,dc=contoso,dc=com" -GroupDN "cn=Group1,ou=All Groups,dc=contoso,dc=com"
    I have that line (with actual DNs) entered in Parameters of the task.
    But when the script runs on the target machine, the values of the parameters in the script are truncated at the spaces.  $ComputerOU is set to "ou=All" and $GroupDN is set to "cn=Group1,ou=all"
    What syntax should I be using the Parameters field of the Task in order to properly pass PowerShell parameter string values that include spaces?
    Tim Curwick
    MadWithPowerShell.com

    Thank you, TC, but I am not calling the parameters from within PowerShell.
    The parameters are in the settings of a task sequence task to be used by the task to launch a script.  The syntax I am using would be correct for use within PowerShell or from a command line or batch script, but SCCM appears to be doing some parsing
    before or while it is passing them to the script, possibly dropping the quotes which causes mishandling of the spaces in the string values.
    Historically, it is always challenging to give one application parameters to pass to another application, and the required syntax can get quite tricky when the two application handle quotes or spaces differently, or when the parent application wants to parse
    something intended to be passed on as is to the child application.
    I'm sure someone has already figured out what the syntax needs to be for doing this with an SCCM 'Run PowerShell Script" task, it's just one of those issues that is hard to Google effectively.
    Any other ideas?
    Tim Curwick
    MadWithPowerShell.com

  • Deploy Powershell 3 to Win7 Via SCCM 2012R2

    Is it possible to deploy Powershell 3 to Windows 7 clients using SCCM 2012R2? Or WSUS? 
    I have read a few blogs describing different methods such as dism to repackage the cab file or using a scripted deployment type (Windows6.1-KBxxxxxxxx64.msu /quiet
    /norestart)  but i can not get it to install the update.  My aim is to get the app-v 5 client on windows 7 desktops so powershell 3 is a requirement.
    Has anyone worked out how to deploy it?
    Many Thanks Dave

    If you're clients are currently at PowerShell 2,  I would recommend installing Windows Management Framework 4 instead of 3.  WMF4 has lots of powershell and WMI improvements over WMF3.
    To deploy WMF4, create an Application with two deployment types (one for x86 and one for x64).  The program is pretty simple - you just need something like "WUSA.EXE Windows6.1-KB2819745-x64-MultiPkg.msu /quiet /norestart".  For a detection
    method, the easiest thing to do is a file version check on "%windir%\System32\WindowsPowerShell\v1.0\powershell.exe"
    Use the WMF4 Application object as a pre-requisite for your App-V 5 Client.  
    I hope that helps,
    Nash
    Nash Pherson, Senior Systems Consultant
    Now Micro -
    My Blog Posts
    If you've found a bug or want the product worked differently,
    share your feedback.
    <-- If this post was helpful, please click "Vote as Helpful".

Maybe you are looking for