Skip to content
InvardiaInvardia
Why InvardiaProductsFeaturesPricingCommunity
Docs
All documentation
Product documentationPIM ManagerSecurityInsight
SettingsPIM Manager settingsSecurityInsight settingsEntra Policy Suite settings
ScriptsPIM Manager scriptsSecurityInsight scriptsEntra Policy Suite scriptsInvardia scripts
Error codesPIM Manager error codesSecurityInsight error codes
API and MCPPIM Manager APIPIM Manager MCP toolsSecurityInsight APISecurityInsight MCP tools
SecurityPIM Manager security packSecurityInsight security packEntra Policy Suite security pack
Network and designPIM Manager network guidesPIM Manager command wizardNetwork egressDesign your installationCalculate your cost
SupportSetup scriptsRemote support access
Search the docs
SupportAboutContactBook a demoCustomer portalDesign your installationFree Pro trial

PIM Manager scripts

Remove-PimHybridWorker

PIM for Active Directory: remove the hybrid worker (Azure VM or Azure Arc server)

Part of the PIM Manager release - not a standalone download; it runs via the product's own install command or the updater.

Purpose

Removes the PIM for Active Directory hybrid worker and everything PIM's worker scripts created for it, and prints the Active Directory clean-up for the AD administrator.

When to run it

When you retire a hybrid worker. Run it without -Apply first: it lists what it would delete and what it keeps. -Target Azure for the worker VM New-PimHybridWorkerInfra.ps1 built; -Target Arc for an on-premises Azure Arc server (the server itself is never removed). -StatePath reads the values Deploy-PimHybridWorker.ps1 remembered.

Who may run it

KindRoleScopeWhy
azureRbacContributorthe worker's resource group (Azure VM)deletes the VM, its NIC and disk, the VNet, NAT gateway, public IP, NSG and the empty resource group
azureRbacNetwork Contributorevery VNet the worker was peered with; the private DNS zone (with -PrivateSqlDnsZoneId)deletes the remote-side peerings PIM created and the zone's link to the worker VNet
azureRbacSQL Server Contributorthe PIM SQL serverdeletes the VNet rule 'pimhybridwrk' (Azure VM) or the firewall rules 'pimhybridwrk-arc-<server>-<n>' (Arc)
azureRbacUser Access Administratorthe source container (-SourceContainerId)deletes the worker identity's Storage Blob Data Reader assignment
entraRolePrivileged Role Administratorthe tenantdeletes the worker identity's Microsoft Graph application permission grants (appRoleAssignments)
othermember of the PIM SQL admin groupthe PIM databaseDROP USER of the worker's contained database user
azureRbacAzure Connected Machine Resource Administratorthe Arc machine (-Target Arc)runs Install-PimHybridWorker.ps1 -Phase Remove on the server through run-command

What it changes

WhereActionWhatPermission / roleScopeWhyUndo
Microsoft Graph (the worker identity)removethe application permission grants Grant-PimHybridWorkerAccess.ps1 gives: Group.Read.All, User.Read.All, PrivilegedAssignmentSchedule.Read.AzureADGroup, Mail.Send (when granted)the worker no longer reads the directoryGrant-PimHybridWorkerAccess.ps1
the source containerremoveStorage Blob Data Reader of the worker identitythe worker no longer fetches PIM codeGrant-PimHybridWorkerAccess.ps1
the PIM databaseremovethe contained user -SqlUserName (database user), only when it carries the worker identity's SIDno database access is left behindGrant-PimHybridWorkerAccess.ps1
the PIM SQL serverremoveVNet rule 'pimhybridwrk' (only when it names the worker subnet) / firewall rules 'pimhybridwrk-arc-<server>-<n>'created for the workerNew-PimHybridWorkerInfra.ps1
privatelink.database.windows.net (with -PrivateSqlDnsZoneId)removethe zone's link to the worker VNet; links to other VNets and the zone itself are kept and listedcreated for the workerNew-PimHybridWorkerInfra.ps1 -PrivateSqlDnsZoneId
the worker's Azure resources (Azure VM)removethe remote-side peerings '<remote>-to-pimhybridwrk' and the worker-side peerings, the VM with its NIC and OS disk, the VNet, the NAT gateway and its public IP, the NSG, and the resource group when PIM created it and it is empty -- only resources tagged pim-hybrid-worker=<worker> (or, with -IncludeUntagged, carrying exactly the scripts' name)the worker is retired; nothing PIM did not create is touchedDeploy-PimHybridWorker.ps1 (a new worker; the VM's identity is new, so the grants are re-run)
the Arc server (-Target Arc)removethe worker's six scheduled tasks, its gMSAs' membership of 'Hybrid agent extension applications' and 'log on as a batch job', C:\PIM\app and C:\PIM\bin (logs kept) -- the machine, its agent and identity staythe worker is retiredInstall-PimHybridWorker.ps1 -Phase Configure

What it only reads

  • the subscription's tenant
  • the worker VM / Arc machine and its identity
  • the identity's Graph grants and role assignments
  • the SQL server's rules
  • the peerings on both sides
  • the NAT gateway, public IP, NSG and resource group with their tags
  • the private DNS zone's links

Parameters

ParameterRequiredDefaultWhat it does
-SubscriptionIdyesThe worker's subscription (Azure VM) or the Arc machine's.
-TenantIdyesThe tenant; the script refuses a subscription in another one.
-TargetyesAzure (the worker VM) or Arc (an on-premises Azure Arc server). Read from -StatePath when given there.
-ResourceGroupnorg-pimhybridwrkAzure: the worker's resource group.
-VmNamenoPIMHYBRIDWRKAzure: the worker VM (the tag value pim-hybrid-worker).
-VnetNamenovnet-pimhybridwrkAzure: the worker VNet.
-NatGatewayNamenonatgw-<vmname>Azure: the NAT gateway Set-PimHybridWorkerEgress.ps1 created.
-PublicIpNamenopip-<vmname>Azure: the NAT gateway's public IP.
-PrivateSqlDnsZoneIdnoThe privatelink.database.windows.net zone the build linked; its link to the worker VNet is deleted.
-IncludeUntaggednofalseA worker built before the tags: also accept untagged resources carrying exactly the scripts' names in -ResourceGroup. Check the plan first.
-NoGuestChecknofalseAzure: do not read the products registered on the VM (C:\ProgramData\HybridWorkerHost\guests) before removing it. Only when the VM cannot run commands and you know no other product's worker is on it; without it, a VM whose registry cannot be read is kept.
-ArcMachineResourceIdnoArc: the machine's resource id (required for -Target Arc). The machine is never removed.
-ArcApiVersionno2024-07-10Microsoft.HybridCompute api-version.
-PrintOnlynofalseArc: write the self-contained removal script for the server's administrator instead of using run-command.
-SqlServerIdnoThe PIM SQL server: its worker rules and the contained user are removed.
-SqlDatabasenoPimPlatformThe PIM database.
-SqlUserNamenoPIMHYBRIDWRKThe worker's contained user.
-KeepSqlUsernofalseLeave the database user in place.
-SourceContainerIdnoThe source container whose Storage Blob Data Reader assignment is removed.
-AdDomainnoAD (printed only): the NetBIOS domain name.
-GmsaNamenogMSA-PIM-L1-T0AD (printed only): the worker gMSA.
-GmsaOunoAD (printed only): the OU holding the gMSAs and their groups.
-ServerGmsaNamenoAD (printed only): the server-onboarding gMSA, when used.
-ServerOunoAD (printed only): the OUs the servers GPO is linked to.
-ServerAdminGpoNamenoPIM for AD: <ServerGmsaName>-PermissionGroup is local administrator (servers)AD (printed only): the servers GPO's name.
-ComputerOunoAD (printed only): the OU of the worker VM's computer account.
-GroupsOunoAD (printed only): the OU where the PermissionGroup holds rights.
-AdminAccountsOunoAD (printed only): the admin-account OUs where the PermissionGroup holds rights.
-GrantProtectedGroupMembershipnofalseAD (printed only): the worker was given the AdminSDHolder right.
-StatePathnoA Deploy-PimHybridWorker.ps1 state file: every value not given is read from it.
-ApplynofalseDelete. Without it the script only prints the plan.
-PollSecondsno10How often a delete is checked until the resource is gone.

Preview with -WhatIf

Without -Apply (or with -WhatIf) it prints every object it would delete, every object it keeps and why, and the Active Directory clean-up; changes nothing.

Undo

Nothing deleted can be restored by this script: build the worker again with Deploy-PimHybridWorker.ps1 (a new VM identity, so the grants are given again). Active Directory is never changed by it.

Network

It connects to: management.azure.com (ARM REST), graph.microsoft.com, the PIM SQL server on 1433 (DROP USER), and login.microsoftonline.com -- browser sign-in or an Invardia support session; no Azure CLI, no PowerShell module

How it runs

Part of the PIM Manager release - not a standalone download; it runs via the product's own install command or the updater.

Release 3.0.70

Every script, identity and permission for your security review: PIM Manager

InvardiaInvardia

See the risk. Control the access.

Products

PIM ManagerSecurityInsightEntra Policy SuiteAll featuresPricingFree 60-day Pro trialBook a demoWhy Invardia

Docs

DocumentationSearch the docsPIM Manager settingsSecurityInsight settingsPIM network guidesCommand wizardNetwork egressPIM Manager design configuratorSecurityInsight design configuratorDesign your installationCalculate your cost

Company

AboutContactCustomer portalSupportHow support worksHow updates reach youSupport in numbersSetup scriptsRemote support accessContact: info@invardia.com

Legal

Terms of saleLicence termsData processingPrivacyCookiesCompany information
© 2026 Invardia – a brand of 2LINKIT, founded and owned by Morten Knudsen · Strandvejen 21A, 6000 Kolding, Denmark · VAT DK39208032 · Contact: info@invardia.com