In PSADT how can we set to Show-InstallationPrompt -Message each day different. for example if i run the package will display first message and the second day i run the same package prompt the second message that i have set. to have multiple message in same script
Random message from the list:
# string array with all messages
[string[]]$messages = "text1","text2","text3" # a list of all messages, separated with commas
# select random message
$randommessage = $messages[(new-object System.Random).next(0,$messages.length)]
# use the random message
Show-InstallationPrompt -Message $randommessage
Based on the day of the week:
# string array with all messages
[string[]]$messages = "text1","text2","text3","text4","text5","text6","text7" # a list of all messages, separated with commas. 1 for each day of the week.
# select message based on day of the week
$daymessage = $messages[([int](get-date).DayOfWeek)]
# use the message
Show-InstallationPrompt -Message $daymessage
Based on the day of the month:
# string array with all messages
[string[]]$messages = "text1","text2","text3","text4","text5","text6","text7","text8" # a list of all messages, separated with commas. 1 for each day of the month. so you need 31
# select message based on day of the month
$daymessage = $messages[((get-date).Day - 1)]
# use the message
Show-InstallationPrompt -Message $daymessage
Hello: I’m trying to run the following i only get Text1 so if i close and re run it wont switch to random message text2, I want if i run every time should switch between random messages, ca n you help me with this I’m not technical with the PowerShell coding,
[string[]]$messages = "text1","text2","text3"
$randommessage = $messages[(new-object System.Random).next(0,$message.length)]
$Answer = Show-InstallationPrompt -Message $randommessage -ButtonRightText 'No' -ButtonLeftText 'Yes' -MinimizeWindows $True -Icon Question
If ($Answer -eq "No") {
Write-Log -Message 'User chose No, so we exit now'
$deployModeSilent=$true
Exit-Script -ExitCode $mainExitCode
}
#else
Write-Log -Message "User chose Yes, so we open up Software Center"
If (Test-Path -Path "$env:windir\CCM\SCClient.exe") {
Start-Process -FilePath "$env:windir\CCM\SCClient.exe" -ArgumentList "SoftwareCenter:Page=Available Software" -WindowStyle Maximized
}
I made a typo there. Copy it again.
I tried copied again it’s the same, maybe the typo message is not saved can you point where it was the type so i can fix that or paste code back here
Thanks for your help
I think the way you wrote it all working but when i add this line specially the $Answer then it will stay with one message, check my previous scrip complete maybe iam missing something.
$Answer = Show-InstallationPrompt -Message $randommessage -ButtonRightText 'No' -ButtonLeftText 'Yes' -MinimizeWindows $True -Icon Question```
is supposed to be
$messages.length
Thank you very much.