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.
CodePudding user response:
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
}
CodePudding user response:
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"))
}