I am trying to execute an powershell script (the script is unzipping the folders in source path with the same name as the .zip folder)
powershell script:
param([string] $sourcepath) $sourcepath = "F:\Worflow\"
function unzip ($file) {
$dirname = $sourcepath +(Get-Item $file).Basename
New-Item -Force -ItemType directory -Path $dirname
expand-archive -path $file -DestinationPath $dirname -F
}
$zipFiles = Get-LongChildItem -Path $sourcepath -Recurse | Where-Object {$_.Name -like "*.zip"}
foreach($file in $zipFiles) { unzip ($file)
}
SSIS Executue process task Arguments:
"-ExecutionPolicy Unrestricted -File C:\MyDataFiles\Unzip.ps1"
The powershell script works fine when ran in PS instance. But the code is failing from SSIS task with an error : Get-LongChildItem : The term 'Get-LongChildItem' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\MyDataFiles\Unzip.ps1:17 char:13 + $zipFiles = Get-LongChildItem -Path $sourcepath -Recurse | Where-Obj ... + ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-LongChildItem:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Anyhelp would be appreciated. The goal is using powershell to zip and unzip folders or files.
Looks like you are attempting to use a command without first loading the module.
Get-LongChildItem is part of the open source module PSAlphaFS
Try importing the module in your script first. Of course it needs to be installed too. ;)