Skip to content

Instantly share code, notes, and snippets.

@shaneis
Created April 24, 2018 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaneis/41d71b8f6caf32bb241227a6dea89d72 to your computer and use it in GitHub Desktop.
Save shaneis/41d71b8f6caf32bb241227a6dea89d72 to your computer and use it in GitHub Desktop.
using a string to invoke a command
$CommandString = @'
if ((Get-Date).Second -lt 15) {
'1st Quarter'
} elseif ((Get-Date).Second -lt 30) {
'2nd Quarter'
} elseif ((Get-Date).Second -lt 45) {
'3rd Quarter'
} else {
'4th Quarter'
}
'@
for ($i = 0; $i -lt 10; $i++) {
[PSCustomObject]@{
Date = Get-Date
ScriptBlock = 'Invoke-Expression'
DateDescription = Invoke-Expression -Command $CommandString
}
Start-Sleep -Seconds 6
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment