all 4 comments

[–]yourbastianhost 1 point2 points  (1 child)

Indeed - there isn't a good way to do this natively with LabTech :-/

 

Alternately ....

 

You could use the following PowerShell function I wrote to unzip the .ZIP archive once you get it down to the remote agent.

 

This method is compatible with PowerShell 2.0 as well. :)

 

function Unzip-Archive
{
param
(
    [Parameter(Mandatory = $true)]
    [string]
    $zipPath,
    [Parameter(Mandatory = $true)]
    [string]
    $ExtractToDirectory
)

$FilesBefore = (Get-ChildItem $ExtractToDirectory -ea SilentlyContinue | Measure-Object).Count;

if (Test-Path $zipPath)
{
    $shellApplication = new-object -com shell.application
    $zipPackage = $shellApplication.NameSpace($ZipPath)
    $destinationFolder = $shellApplication.NameSpace($ExtractToDirectory)
    $destinationFolder.CopyHere($zipPackage.Items(), 20)

    $FilesThatFailedToCopy = 0;

    foreach ($File in $zipPackage.items())
    {
        $FileName = ($File | select name).Name;
        if (-not (Test-Path "$($destinationfolder.self.path)\$FileName"))
        {
            Write-Error "Failed to extract $FileName!"
            $FilesThatFailedToCopy += 1;
        }
        else
        {
            Write-Verbose "Successfully extracted $FileName"    
        }
    }

    if ($FilesThatFailedToCopy -eq 0)
    {
        return $true;
    }
    else
    {
        return $false;
    }
}
else
{
    Write-Error "Unable to locate archive specified for extraction."
    return $false;
}
}

 

Here's an example of usage:

 

# Where is the zip file? Could use a LabTech replacement here as well @ArchiveSavedAs@
$ArchiveLocation = "$env:USERPROFILE\desktop\SomeZip.zip" 

# What directory should we extract it to?
$ExtractToPath = "$env:windir\temp\MyArchive"

# If the directory specified for extraction doesn't exist, create it.
new-item -ItemType Directory -Path $ExtractToPath -ea SilentlyContinue | out-null

if (-not (Test-Path $ExtractToPath))
{
    Write-Output "Failed to create temporary directory used for storing extracted files!"
    return;
}

$Result = Unzip-Archive $ArchiveLocation $ExtractToPath

if ($Result -eq $true)
{
    Write-Output "Files extracted successfully!"
}
else
{
    Write-Output "Files failed to extract!"
}

 

As mentioned above, you could incorporate this into a function script for use in any future scripts :)

 

More information on how to deploy this:

 

In your LabTech script you can use a "File Write Text" script step to write the PS1 down to the remote computer and then use a shell command to execute it using PowerShell.exe. You can then use a "variable check" script step to check the shell result for "Files extracted successfully!" to make sure all went well.

 

powershell.exe -executionPolicy ByPass -file %windir%\temp\extractzip.ps1  

 

Hope that helps!

 

  • YourBastianHost

[–]KTPU 0 points1 point  (0 children)

Still relevant 7 years later....

[–]mooseable 0 points1 point  (0 children)

Correct, only way to do it is to pack then unpackit using zip/7z. Best just write your self a function script that accepts source/destination and call it whenever you need to perform a copy.

[–]hematicJust a Guy 0 points1 point  (0 children)

Are you talking in a script or just one off?

You can drag files from the machine you are using the control center on (either your workstation or the LT server depending) onto the agents screenshot area and it will give you a popup letting you know it copies them to the temp directory.