Home > Enterprise >  How to input and parse data on powershell script
How to input and parse data on powershell script

Time:02-26

I am currently trying to make a simple powershell script .ps1 that will show me the epoch day. I currently have (Get-Date -Year 2022 -Month 12 -Day 31).DayOfYear but I have to go in and edit the file each time for when I am needing to find the specific epoch day.

What do I need to add so that when I start the script it will open powershell and then prompt the user for the year, then month and lastly the day and output the epoch day?

CodePudding user response:

Create a file with the CMD extension, such as DayOfYear.CMD, and place this code in it.

After saving the code, just double click the file to run it.

NOTE: Saving as CMD works in recent version of Windows, but in another OS, save and run as any other PowerShell script.

<# :
@ECHO OFF
    SET f0=%~f0
    PowerShell -NoProfile -ExecutionPolicy RemoteSigned -Command "$Input | & ([scriptblock]::Create((get-content -raw '           
  • Related