I'm struggling to pass my arguments to my custom made function.
This works fine:
Delete-OldFiles -Target $Target -OlderThanDays $OlderThanDays -LogName Auto_Clean.log
These don't work at all:
# (using -ScriptBlock ${Function:Delete-OldFiles} for all calls)
Invoke-Command -ArgumentList ( ".$Target", ".$OlderThanDays", ".$LogName Auto_Clean.log")
Invoke-Command -ArgumentList @("$Target", "$OlderThanDays", "Auto_Clean.log")
Invoke-Command -ArgumentList @({-OlderThanDays "10", -Target "E:\Share\Dir1", -LogName "Auto_Clean.log"})
Invoke-Command -ArgumentList (,@('$Target','$OlderThanDays','Auto_Clean.log'))
Can you help me on how to pass the following parameters correctly:
Param(
[Parameter(Mandatory=$False,Position=1)]
[String]$Server,
[Parameter(Mandatory=$True,Position=2)]
[ValidateScript({Test-Path $_})]
[String]$Target,
[Parameter(Mandatory=$True,Position=3)]
[Int]$OlderThanDays,
[Parameter(Mandatory=$True,Position=4)]
[String]$LogName,
[switch]$CleanFolders
)