First of all, you can do all this with the console. If you can, just do it. But I Always try to automate my work and when I create a new Citrix image i need to clear the PXE for my server before I can start a new deployment.

I ran into some errors which I solved in this script. For example:

Set-Location : Cannot find drive. A drive with the name 'ABC' does not exist.
At line:3 char:1
+ Set-Location ABC:
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (ABC:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
Get-CMDevice : This command cannot be run from the current drive. To run this command you must first connect to a Configuration Manager drive.
At line:5 char:13
+ $CMDevice = Get-CMDevice -Name $Computername
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : DeviceError: (Microsoft.Confi...etDeviceCommand:GetDeviceCommand) [Get-CMDevice], InvalidOperationException
    + FullyQualifiedErrorId : CommandCannotExecuteFromCurrentDrive,Microsoft.ConfigurationManagement.Cmdlets.Collections.Commands.GetDeviceCommand

Because I use a service account, I needed to create the PSDrive manually. The “drive” normally is created when you open the console. But I have never opened the console with my service account. 

Here is the small script I created:

$Computername = "CTX01"
$CMSite = "ABC"

# Import the modules, you can only do this on the computer where the console is installed.
Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'

# Create a PSDrive with the site name
New-PSDrive -Name "ABC" -PSProvider "AdminUI.PS.Provider\CMSite" -Root "" -Description "ABC Primary Site Server"

# Set the site as current location
Set-Location "$($CMSite):"

# Get device object
$CMDevice = Get-CMDevice -Name $Computername

# If you have 1 result, everthing is OK and you can clear its PXE
if($CMDevice.Count -eq 1) {
    # Clear PXE for device $CMDevice
    Clear-CMPxeDeployment -DeviceName $CMDevice.Name -Verbose

I hope it helps you!