Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Problems executing a script

Hello,

 

I am trying to execute a powershell script that is called from a batch file. I have done a copy step of the powershell script that contains some lines like these:

Get-AppxPackage *messaging* | Remove-AppxPackage -AllUsers
Get-AppxPackage *gethelp* | Remove-AppxPackage -AllUsers
Get-AppxPackage *mspaint* | Remove-AppxPackage -AllUsers
Get-AppxPackage *wallet* | Remove-AppxPackage -AllUsers
Get-AppxPackage *oneconnect* | Remove-AppxPackage -AllUsers
Get-AppxPackage *DesktopAppInstaller* | Remove-AppxPackage -AllUsers
Get-AppxPackage *feedback* | Remove-AppxPackage -AllUsers
Get-AppxPackage *windowsstore* | Remove-AppxPackage -AllUsers

and then anorther step with command calling execute.cmd that contains this line:

PowerShell -NoProfile -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Unrestricted -File ""C:\RemoveApp.ps1""' -Verb RunAs}";

I need it because I have to elevate powershell in admin contest (otherwise it fails even if I am using domanin admins credentials)

If i double clic the execute.cmd on target machine it works, runs RemoveApp.ps1 and Appx packages disappear in all user profiles on target machine. If I try from PDQ Deploy I have got a success code but nothing happens.

Someone can give me some help?  

1

Comments

5 comments
Date Votes
  • Mauro,

    Could you please export the PDQ Deploy package and post it here?

    1
  • <?xml version="1.0" encoding="utf-8"?>
    <AdminArsenal.Export Code="PDQDeploy" Name="PDQ Deploy" Version="18.2.12.0" MinimumVersion="15.0">
    <Package>
    <CurrentLibraryPackageVersionId value="null" />
    <PackageDefinition name="Definition">
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <CopyMode>Default</CopyMode>
    <DelayedApprovalTimeSpan>7.00:00:00</DelayedApprovalTimeSpan>
    <DownloadApprovalMode>Manual</DownloadApprovalMode>
    <InventoryScanProfileId value="null" />
    <IsDownloadApprovalModeInherited value="true" />
    <ScanAfterDeployment value="null" />
    <Steps type="list">
    <CommandStep>
    <Command>"\\FEMPC0650\E\setup.exe" /Auto Upgrade /MigrateDrivers All /ShowOOBE none /Compat IgnoreWarning /Telemetry Disable</Command>
    <Files></Files>
    <SuccessCodes>0</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Bits64</Architecture>
    <Version>Windows10</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>NoLoggedOnUser</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <Title></Title>
    <TypeName>Command</TypeName>
    <IsEnabled value="false" />
    <IsPostStep value="false" />
    <IsPreStep value="false" />
    </CommandStep>
    <FileCopyStep>
    <AllowOverwrite value="false" />
    <CopyAllFiles value="false" />
    <FilePatternsText></FilePatternsText>
    <IgnoreOverwriteErrors value="false" />
    <IncludeSubFolders value="false" />
    <Mode>SingleFile</Mode>
    <Source>\\FEMPC0650\C$\Supporto\RemoveApp.ps1</Source>
    <Target>C:\</Target>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <Title>File Copy</Title>
    <TypeName>FileCopy</TypeName>
    <IsEnabled value="true" />
    <IsPostStep value="false" />
    <IsPreStep value="false" />
    </FileCopyStep>
    <CommandStep>
    <Command>\\fempc0650\c$\supporto\startps.cmd</Command>
    <Files></Files>
    <SuccessCodes>0</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <Title></Title>
    <TypeName>Command</TypeName>
    <IsEnabled value="true" />
    <IsPostStep value="false" />
    <IsPreStep value="false" />
    </CommandStep>
    </Steps>
    <Timeout value="60" />
    <UseCustomTimeout value="false" />
    <RunAs>Admin</RunAs>
    </PackageDefinition>
    <Description></Description>
    <NewLibraryPackageVersionId value="null" />
    <OriginalId value="null" />
    <Version></Version>
    <IsAutoDownload value="false" />
    <FolderId value="4" />
    <LibraryPackageVersionId value="null" />
    <Name>W10_1909</Name>
    <Path>Packages\Install\Experimental\W10_1909</Path>
    <PackageDisplaySettings name="DisplaySettings">
    <DisplayType>Normal</DisplayType>
    <IconKey>Icon-Package</IconKey>
    <SortOrder value="7" />
    </PackageDisplaySettings>
    </Package>
    </AdminArsenal.Export>

    1
  • Ok, thanks. Try this version, I disabled your steps and added my own. I consolidated your File Copy and Command steps as a single Install step:

    <?xml version="1.0" encoding="utf-8"?>
    <AdminArsenal.Export Code="PDQDeploy" Name="PDQ Deploy" Version="18.1.38.0" MinimumVersion="15.0">
    <Package>
    <CurrentLibraryPackageVersionId value="null" />
    <PackageDefinition name="Definition">
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>AllWorkstations</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <CopyMode>Default</CopyMode>
    <DelayedApprovalTimeSpan>7.00:00:00</DelayedApprovalTimeSpan>
    <DownloadApprovalMode>Manual</DownloadApprovalMode>
    <InventoryScanProfileId value="null" />
    <IsDownloadApprovalModeInherited value="true" />
    <ScanAfterDeployment value="null" />
    <Steps type="list">
    <CommandStep>
    <Command>"\\FEMPC0650\E\setup.exe" /Auto Upgrade /MigrateDrivers All /ShowOOBE none /Compat IgnoreWarning /Telemetry Disable</Command>
    <Files></Files>
    <SuccessCodes>0</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Bits64</Architecture>
    <Version>Windows10</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>NoLoggedOnUser</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <Title></Title>
    <TypeName>Command</TypeName>
    <IsEnabled value="false" />
    <IsPostStep value="false" />
    <IsPreStep value="false" />
    </CommandStep>
    <FileCopyStep>
    <AllowOverwrite value="false" />
    <CopyAllFiles value="false" />
    <FilePatternsText></FilePatternsText>
    <IgnoreOverwriteErrors value="false" />
    <IncludeSubFolders value="false" />
    <Mode>SingleFile</Mode>
    <Source>\\FEMPC0650\C$\Supporto\RemoveApp.ps1</Source>
    <Target>C:\</Target>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <Title>File Copy</Title>
    <TypeName>FileCopy</TypeName>
    <IsEnabled value="false" />
    <IsPostStep value="false" />
    <IsPreStep value="false" />
    </FileCopyStep>
    <CommandStep>
    <Command>\\fempc0650\c$\supporto\startps.cmd</Command>
    <Files></Files>
    <SuccessCodes>0</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <Title></Title>
    <TypeName>Command</TypeName>
    <IsEnabled value="false" />
    <IsPostStep value="false" />
    <IsPreStep value="false" />
    </CommandStep>
    <InstallStep>
    <CustomCommandLine></CustomCommandLine>
    <FileName>\\fempc0650\c$\supporto\startps.cmd</FileName>
    <Files>\\FEMPC0650\C$\Supporto\RemoveApp.ps1</Files>
    <IncludeDirectory value="false" />
    <LeaveInstallFile value="false" />
    <MsiOperation>Install</MsiOperation>
    <MsiQuiet value="true" />
    <MsiRestart>Never</MsiRestart>
    <Parameters></Parameters>
    <SuccessCodes>0,1641,3010,2359302</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>AllWorkstations</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <ConditionMode>None</ConditionMode>
    <InventoryCollectionId value="null" />
    <InventoryCollectionName></InventoryCollectionName>
    <TypeName>Collection</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <Title>Execute startps.cmd</Title>
    <TypeName>Install</TypeName>
    <IsEnabled value="true" />
    <IsPostStep value="false" />
    <IsPreStep value="false" />
    </InstallStep>
    </Steps>
    <Timeout value="60" />
    <UseCustomTimeout value="false" />
    <RunAs>Admin</RunAs>
    </PackageDefinition>
    <Description></Description>
    <NewLibraryPackageVersionId value="null" />
    <OriginalId value="null" />
    <Version></Version>
    <IsAutoDownload value="false" />
    <FolderId value="45" />
    <LibraryPackageVersionId value="null" />
    <Name>W10_1909</Name>
    <Path>Private Packages\PDQ Support Forums\W10_1909</Path>
    <PackageDisplaySettings name="DisplaySettings">
    <DisplayType>Normal</DisplayType>
    <IconKey>Icon-Package</IconKey>
    <SortOrder value="7" />
    </PackageDisplaySettings>
    </Package>
    </AdminArsenal.Export>

    0
  • I am afraid that it isn.t working, there is some strange permissions problems, I am trying deploymentt toward a win 10 1703 (the idea is to update old machines and throw away appx garbage, after 1909 update). I ve tryed almost any combination, copying files on target and executing, using a share folder (in case some path problems), inserting command straight from comman line ... for an example if I call cmd on targed machine (no runas as administrator a simple cmd but with domain admin user) and I paste the cmd string, having ps1 script in correct place it works, no way with pdq deploy ...

     

    By the way I have seen just now that compacting in a single step makes cmd wrong, it is calling c:\removeapp.ps1 but now removeapp.ps1 is copyied in c:\windows\Admin Arsenal\ ... So I have removed C:\, but I dont know if cmd is accepting a relative path ... I used C:\ and two steps to be sure of invoking an existent file.

    1
  • Try using pathvariables instead of hardcoded paths in your scripts.

     

    For example (batch) for current path: %~dp0

    For example (powershell) for current script path: $PSScriptRoot

    For example (powershell) for C: : $env:SystemDrive

    etc..

    1