Skip to content

Instantly share code, notes, and snippets.

@toddboyd
Last active June 20, 2021 17:13
Show Gist options
  • Save toddboyd/7e9e906697e6f6afeeec2161fe2ad546 to your computer and use it in GitHub Desktop.
Save toddboyd/7e9e906697e6f6afeeec2161fe2ad546 to your computer and use it in GitHub Desktop.
Create Scratch Org PowerShell Script
param([string] $orgName, [int] $duration, [boolean]$debugMode)
if (!$orgName) {
# If no scratch org name is given, use a default name
$orgName = "defaultScratchOrgName";
}
if (!$duration) {
# if no duration is provided, use default
$duration = "7";
}
# Create Scratch Org
Write-Host -ForegroundColor green "Creating scratch org: $orgName..."
& sfdx force:org:create -a $orgName -d $duration -f config\project-scratch-def.json
if ($LASTEXITCODE -ne 0) {
exit 1
}
if ($debugMode) {
# Set debug mode = true
Write-Host -ForegroundColor green "Setting debug mode..."
& Write-Output "update new User(Id = UserInfo.getUserId(), UserPreferencesUserDebugModePref=true);" | sfdx force:apex:execute -u $orgName
if ($LASTEXITCODE -ne 0) {
exit 1
}
}
Write-Host ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment