본문 바로가기
ICT

[PowerShell] MECM(Microsoft EndPoint Configuration Management) Script Run/Reinstall Client Bulkily

by NeoSailer 2023. 12. 21.

[Requirements]

For vulnerability management in terms of Windows monthly update, it is a burdensome work either running remediation script or reinstalling MECM client for each PC manually.

 

Write PowerShell script which can run script or reinstall commands for a big list of PC

 

[OS] 

Windows clinet/server

 

[Development Language]

PowerShell

 

[IDE]

PowerShell ISE

 

[Setting]

- RDP MECM(Microsoft EndPoint Configuration Manager) server

 

- Run PowerShell with admin. right

 

- Prepare a list of PC with csv file

<<CSV Format>>

  • File format should be "csv"
  • Computer names should be listed under "Asset Name" column
  • Remove "rotork.co.uk" after the computer name if exists
  • Modify csv file path and name in Import-CSV function

 

[Code]

#### setting for Configuration Manager module and site
cd "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
Import-Module .\ConfigurationManager.psd1
Set-Location RB1: #Rotork Bath Primary Site
 
#### Variables
$ScriptID = "1CDE1F81-A805-4D25-A2FF-2F8F4BE8BFD1" #EndPoint SUP Remediation script ID
 
#### Fetching PC names from SCV file
$ComputerNames = Import-CSV -Path "C:\Temp\VM_vulns_rtrkc2ay_20231221.csv"
$Computers = $ComputerNames."Asset Name"
 
#### Running script 
$Computers | % {Invoke-CMScript -Device (Get-CMDevice -Name $_) -ScriptGuid $ScriptID}
 
#### Re-installing client
$Computers | % {Install-CMClient -DeviceName $_ -SiteCode "RB1" -AlwaysInstallClient $True -IncludeDomainController $True}

 

 

[Test]

Done successfully

 

[Lesson Learned]

There is always a way to shorthen/automate task, do not doubt

반응형

댓글