Cant access file properties

Can somebody help me with this.I have code where I need to use GetType and FullName for $file variable.For some reason it does not recognise this functions.

param (

Add-Type -AssemblyName System.IO.Compression.FileSystem
function Zip {
param([string]$folderInclude, [string]$outZip)
[System.IO.Compression.CompressionLevel]$compression = “Optimal”
$ziparchive = [System.IO.Compression.ZipFile]::Open( $outZip, “Update”)

$realtiveTempFolder = (Resolve-Path $tempFolder -Relative).TrimStart(".")

foreach($file in (Get-ChildItem $folderInclude -Recurse)){

if($file.GetType().ToString() -ne “System.IO.DirectoryInfo”){
$relpath = “”
$relpath = (Resolve-Path $file.FileName -Relative)

  $relpath = $file.Name
   $relpath = $relpath.Replace($realtiveTempFolder,"")
   $relpath = $relpath.TrimStart(".\").TrimStart("\\");

 [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($ziparchive,$file.FullName,$relpath,$compression) || Out-Null




$Directory = Split-Path -Path $name -Parent
$tempFolder = $Directory + “\Populate-Word-DOCX”
Zip $tempFolder $name

Why not just use


Hi Dragan11 and welcome to the forums!

First, please have your code properly formatted by following this:

I’m checking the parameters and properties on PSVersion 7.4.1. When I do a $file | gm, the fileName property that you’re referring does not exist. I did verify that the FullName property and GetType() function both exist. What PSVersion are you on?

I don’t see why you would want to reinvent the wheel when a cmdlet already exists as neemobeer suggested using Compress-Archive.

One possible reason is that depending on the PowerShell version, Compress-Archive is limited to 2GB.