I want import powershell cmd stored in txt file var1.txt inside a scr3.ps1 script inside Powershell ISE and execute the cmds.
var1.txt file data
time=(Get-Date).AddYears(-1)
extn=@("*.mp3", "*.jpg")
path=E:\marathi\Lavani
scr3.ps1 file data
$ConfigFile = "E:\marathi\Lavani\var1.txt"
#Creating an empty hash table
$ConfigKeys = @{}
#Pulling, separating, and storing the values in $ConfigKey
Get-Content $ConfigFile | ForEach-Object {
$Keys = $_ -split "="
$ConfigKey += @{$Keys[0]=$Keys[1]}
}
$extn2 = $ConfigKey.extn
$path2 = $ConfigKey.path
$time2 = $ConfigKey.time
$time2
$extn2
$path2
Get-ChildItem -Include $extn2 -Path $path2 -Recurse | Where-Object {($_.LastWriteTime -lt $time2)}
the output of $time2, $extn2, $path2 is as follows
(Get-Date).AddYears(-1)
@("*.mp3", "*.jpg")
E:\marathi\Lavani
But the required output is
26 May 2022 11:32:46 AM
*.mp3
*.jpg
E:\marathi\Lavani
how to import PowerShell command from txt file into PowerShell .ps1 file and execute the commands as well?