I am trying to pass folder path to Compress Archive function through clipboard but it shows me error. I am using following code:
$toZipDirectory = 'C:\Users\sadam.shaikh\Desktop\Automate\'
$zipFilePath = 'C:\Users\sadam.shaikh\Desktop\Automate\zip.zip'
$Newness= Get-ChildItem -Path $toZipDirectory | Where-Object {$_.PSIsContainer} |
Sort-Object LastWriteTime -Descending | Select-Object -First 1 | % { $_.FullName } | Clip
$directoryname= Get-Clipboard
Compress-Archive -Path $directoryname -DestinationPath $zipFilePath
Error: Compress-Archive : Cannot validate argument on parameter 'Path'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:6 char:24 Compress-Archive -Path $directoryname -DestinationPath $zipFilePath CategoryInfo : InvalidData: (:) [Compress-Archive], ParameterBindingValidationException FullyQualifiedErrorId : ParameterArgumentValidationError,Compress-Archive