Skip to content

Commit 4c01cbc

Browse files
committed
Remove Azure Arc Setup if installed. Reboot will happend automaticaly.
1 parent 7b6a911 commit 4c01cbc

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

Windows/Remove-AzureArc.ps1

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#requires -version 5.1
2+
3+
<#
4+
.SYNOPSIS
5+
Remove Azure Arc Setup if installed. Reboot will happend automaticaly.
6+
7+
.DESCRIPTION
8+
Remove Azure Arc Setup if installed. Reboot will happend automaticaly.
9+
10+
.EXAMPLE
11+
Remove-AzureArc.ps1
12+
13+
.NOTES
14+
Author : Fabian Niesen
15+
Filename : Remove-AzureArc.ps1
16+
Requires : PowerShell Version 5.1
17+
18+
19+
Version : 1.0
20+
21+
History : FN 06.03.2024 Initiale Version
22+
.LINK
23+
https://github.com/InfrastructureHeroes/Scipts
24+
#>
25+
#REGION Functions
26+
Function Get-PendingRebootStatus {
27+
<#
28+
.Synopsis
29+
This will check to see if a server or computer has a reboot pending.
30+
For updated help and examples refer to -Online version.
31+
32+
.NOTES
33+
Name: Get-PendingRebootStatus
34+
Author: theSysadminChannel, Fabian Niesen
35+
Version: 1.2 FN
36+
DateCreated: 2018-Jun-6
37+
DateModified: 2023-Jan-20
38+
39+
.LINK
40+
https://thesysadminchannel.com/remotely-check-pending-reboot-status-powershell
41+
42+
43+
.PARAMETER ComputerName
44+
By default it will check the local computer.
45+
46+
.EXAMPLE
47+
Get-PendingRebootStatus -ComputerName PAC-DC01, PAC-WIN1001
48+
49+
Description:
50+
Check the computers PAC-DC01 and PAC-WIN1001 if there are any pending reboots.
51+
#>
52+
53+
[CmdletBinding()]
54+
Param ()
55+
56+
BEGIN {}
57+
58+
PROCESS {
59+
Try {
60+
$Computer = $env:COMPUTERNAME
61+
$PendingReboot = $false
62+
$HKLM = [UInt32] "0x80000002"
63+
$WMI_Reg = [WMIClass] "\\$Computer\root\default:StdRegProv"
64+
if ($WMI_Reg) {
65+
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")).sNames -contains 'RebootPending') {$PendingReboot = $true ; Write-output "Component Based Servicing: RebootPending"}
66+
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")).sNames -contains 'RebootRequired') {$PendingReboot = $true ; Write-output "WindowsUpdate: RebootRequired"}
67+
if (($WMI_Reg.EnumKey($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager")).sNames -contains 'PendingFileRenameOperations') {$PendingReboot = $true ; Write-output "Session Manager: PendingFileRenameOperations"}
68+
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update")).sNames -contains 'PostRebootReporting') {$PendingReboot = $true ; Write-output "WindowsUpdate: PostRebootReporting"}
69+
if (($WMI_Reg.EnumKey($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager")).sNames -contains 'PendingFileRenameOperations2') {$PendingReboot = $true ; Write-output "Session Manager: PendingFileRenameOperations2"}
70+
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")).sNames -contains 'RebootInProgress') {$PendingReboot = $true ; Write-output "Component Based Servicing: RebootInProgress"}
71+
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")).sNames -contains 'PackagesPending') {$PendingReboot = $true ; Write-output "Component Based Servicing: PackagesPending"}
72+
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\ServerManager")).sNames -contains 'CurrentRebootAttempts') {$PendingReboot = $true ; Write-output "ServerManager: CurrentRebootAttempts"}
73+
if (($WMI_Reg.EnumKey($HKLM,"SYSTEM\CurrentControlSet\Services\Netlogon")).sNames -contains 'JoinDomain') {$PendingReboot = $true ; Write-output "Netlogon: JoinDomain"}
74+
#Checking for SCCM namespace
75+
$SCCM_Namespace = Get-WmiObject -Namespace ROOT\CCM\ClientSDK -List -ComputerName $Computer -ErrorAction Ignore
76+
if ($SCCM_Namespace) {
77+
if (([WmiClass]"\\$Computer\ROOT\CCM\ClientSDK:CCM_ClientUtilities").DetermineIfRebootPending().RebootPending -eq $true) {$PendingReboot = $true ; Write-output "SCCM: RebootPending"}
78+
}
79+
}
80+
} catch {
81+
Write-Error $_.Exception.Message
82+
} finally {
83+
#Clearing Variables
84+
$null = $WMI_Reg
85+
$null = $SCCM_Namespace
86+
IF ($PendingReboot) { $reboot = $true }
87+
}
88+
}
89+
90+
END { Return $PendingReboot }
91+
}
92+
#ENDREGION Functions
93+
$AzureArc = $( (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction SilentlyContinue ).UBR -ge 2031)
94+
IF ( -not $AzureArc)
95+
{ Write-Output "Patchlevel is not high enough for Azure Arc - No action required " }
96+
Else {
97+
# Get-WindowsFeature -Name AzureArcSetup
98+
IF ( (get-WindowsFeature -Name AzureArcSetup).InstallState -like "Installed" ) {Write-Warning "AzureArc is Installed - Remove Feature Restart required" ; Uninstall-WindowsFeature -Name AzureArcSetup -Restart:$false -confirm:$false }
99+
ELSE { Write-Output "Windows Arc is not installed"}
100+
IF ( Get-PendingRebootStatus ) {
101+
Write-Warning "Reboot required - Will reboot in 60 sec. Use >Shutdown.exe /a< to abort."
102+
shutdown.exe /t 60 /r /c "Reboot required" /d p:2:4
103+
}
104+
}

0 commit comments

Comments
 (0)