Powershell Script not working through SCCM

Variable $LastDP i set within a script loses its value while deploying through SCCM . I have tested this script in SYSTEM context using psexec -i -s cmd.exe and it works but it seems to return null value via SCCM. Also tried to set variable scope as global but it didn't work. It inserts $laspDp value when get to this part "$config1 | % { $_.Replace("\server", "\$LastDP\SMSPKGE$\C02076B8\SA") } | Set-Content .\Configuration.Project.mvp1.v001_cdnSA.xml" when ran it as an admin in ISE and also when ran script in SYSTEM context which i believe SCCM use too. when ran through CM/software center it loose the $lastDp value and the entry in xml file is "\\SMSPKGE$\C02076B8\SA". Command line to run the script

%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -Noprofile -file "%currentdir%\script.ps1

  • This error is caused by the PowerShell Execution Policy. By default, the PowerShell Execution policy is set to Restricted. This means that PowerShell scripts won't run at all. Execution Policies are not designed as a security model, but more to prevent the accidental execution of a PowerShell script.

    Methods to fix-

    1. Initiate a full system scan
    full system scan
    In some situations, a malware attack might be the reason why Windows PowerShell is not working properly. So, the first thing to do is to initiate a security scan.

    Chances are you got infected with Poweliks, a malware that interferes with PowerShell. The file associated with this virus are dllhost.exe *32 or dllhst3g.exe *32 and can be usually stopped from Task Manager.

    Expert Tip: Some PC issues are hard to tackle, especially when it comes to corrupted repositories or missing Windows files. If you are having troubles fixing an error, your system may be partially broken. We recommend installing Restoro, a tool that will scan your machine and identify what the fault is.
    Click here to download and start repairing.

    Now, in this case, you need to use an antivirus tool and scan your Windows 10 system for possible infected files. The security program should find and remove the malware automatically.

    2. Initiate a clean boot
    Press the Win+R keyboard hotkeys in order to launch the run box.
    There, type msconfig and press Enter.msconfig windows 10
    From System Configuration, go to the General tab.
    From there, under Selective Startup uncheck the lload startup items field.
    Next, switch to the Services tab.
    Click on the hide all Microsoft services checkbox and afterward click on Disable all.clean boot windows 10
    Now, switch to the Startup tab and click on the Open task manager link.click on the Open task manager link
    From Task Manager disable all Startup programs.
    Save your changes and close these windows.
    Restart your Windows 10 system.

    You can see if a software conflict is causing Windows PowerShell malfunctions by initiating a clean boot. In this way, you can start the Windows 10 system only with default features.

    If the Windows PowerShell has stopped working error is not displayed after the clean boot is performed it means that there is a software conflict, so you need to remove the program that stands behind this issue.


    3. Disable and re-enable Windows PowerShell
    Press on Win+X hotkeys and select Control Panel.
    From Control Panel switch to category.
    From the list that’s displayed, it’s time to choose Uninstall – located under Programs.Uninstall option
    From the left panel of the main window click on Turn Windows features on or off.
    Scroll down and locate the Windows PowerShell entry.
    Uncheck the PowerShell feature.
    Save and apply your changes.
    Restart your Windows 10 computer.
    Afterward, repeat the steps from above and re-enable the Windows PowerShell feature.

    This may help you,

    Rachel Gomez