Powershell - Import File based on Day

dann47
dann47 used Ask the Experts™
on
I have a powershell script, that is going to be used by patching, at the moment i am having a different script for each day, that is importing a file based on that day - IE Monday Tuesday etc.  I have 2 variables that i am having to change on each script.  So question is, is there a way i can get powershell to import the file name based on day ?

For example, if a Thu import the below

#Variables For File Names

$fileName = "C:\Patching\Schedule\WinA-Test_Thu.txt"
$csvname =  "C:\Patching\Schedule\WinA-Test_Thu.csv"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Try it like this:
$DowShort = (Get-Date).DayOfWeek.ToString().SubString(0, 3)
$fileName = "C:\Patching\Schedule\WinA-Test_$($DowShort).txt"
$csvname =  "C:\Patching\Schedule\WinA-Test_$($DowShort).csv"

Open in new window

Brilliant, many thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial