Reputation: 1060
I need to convert what looks like a pretty simple bash script to powershell but I'm pretty new to both.
The original script is:
alias cptimestamp="date +"%Y%m%d%H%M" | clip"
I've gotten this far but I'm not sure:
function cptimestamp {
cptimestamp="date +"%Y%m%d%H%M" | clip"
}
I'm having a hard time figuring out what the 'clip' part does.
Upvotes: 2
Views: 4416
Reputation: 24545
If the purpose of your PowerShell function is to copy the current date and time to the Windows clipboard, I would probably use this:
function cptimestamp {
[Windows.Forms.Clipboard]::SetText((Get-Date -Uformat "%Y%m%d%H%M"))
}
Or alternatively:
function cptimestamp {
[Windows.Forms.Clipboard]::SetText((Get-Date -Format "yyyyMMddhhmmss"))
}
Upvotes: 2
Reputation: 174485
The equivalent of date +"%Y%m%d%H%M"
in PowerShell would be:
Get-Date -UFormat "%Y%m%d%H%M"
So your function should probably look like this:
function cptimestamp {
Get-Date -UFormat "%Y%m%d%H%M" |Set-ClipBoard
}
Upvotes: 6