Overview
This script automates the process of setting up an administrator account with secure settings in SCCM. It includes steps to create, manage, and distribute a package using the SCCM PowerShell module.
Instructions
- Set Up Variables:
- Define the necessary variables for your SCCM server, site code, script name, and other details.
# Define Variables $SCCMServer = "\\YourSCCMServer" $SiteCode = "YourSiteCode" $ScriptName = "Administrator-Account-Configuration" $ScriptDescription = "Sets up the administrator account with secure settings." $PackageSourcePath = "C:\Scripts\$ScriptName"
- Load the SCCM PowerShell Module and Connect to the SCCM Site:
- Load the SCCM module and connect to your SCCM site using the defined site code.
# Load SCCM PowerShell Module Import-Module "$($Env:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" -Force # Connect to the SCCM Site cd "$SiteCode`:"
- Check for Existing Packages and Remove if Necessary:
- Ensure there are no conflicting packages by removing any existing packages with the same name.
# Check if a package with the same name exists and delete it $ExistingPackages = Get-CMPackage -Name $ScriptName -ErrorAction SilentlyContinue if ($ExistingPackages) { foreach ($Package in $ExistingPackages) { Remove-CMPackage -Id $Package.PackageID -Force } }
- Create the Package Source Directory and Script:
- Create the directory for the package if it doesn’t exist and generate the PowerShell script content.
# Create the Package Source Directory if it does not exist if (!(Test-Path -Path $PackageSourcePath)) { New-Item -ItemType Directory -Path $PackageSourcePath -Force } # Create the PowerShell script $ScriptContent = @' # Sets up the administrator account with secure settings net user Administrator
/add y '@ $ScriptPath = "$PackageSourcePath\Administrator-Account-Configuration.ps1" Set-Content -Path $ScriptPath -Value $ScriptContent - Create and Distribute the SCCM Package:
- Create the SCCM package and program, and distribute the package to the specified distribution point.
# Create the SCCM Package $Package = New-CMPackage ` -Name $ScriptName ` -Description $ScriptDescription ` -Path $PackageSourcePath # Create a Program for the Package $Program = New-CMProgram ` -PackageName $ScriptName ` -StandardProgramName $ScriptName ` -CommandLine "powershell.exe -ExecutionPolicy Bypass -File Administrator-Account-Configuration.ps1" ` -ProgramRunType "WhetherOrNotUserIsLoggedOn" # Distribute the Package to the Distribution Point but do not deploy Start-CMContentDistribution ` -PackageName $ScriptName ` -DistributionPointName "YourDistributionPointName"
Script Explanation
This script automates the creation, configuration, and distribution of an SCCM package that sets up an administrator account with predefined secure settings. The script also includes steps to ensure that any previous version of the package is removed, preventing conflicts.
Tags:
#SCCM #PowerShell #Automation #PackageManagement #SystemAdministration