# My first PowerShell script, also my first C# code

**URL:** <https://forums.powershell.org/t/my-first-powershell-script-also-my-first-c-code/322>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/my-first-powershell-script-also-my-first-c-code/322 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/my-first-powershell-script-also-my-first-c-code/322/1 "2011-12-31T18:30:00Z")

</div>

by GregL65 at 2012-11-09 09:41:54

> I’m familiar with coding in VBA but this is my first PowerShell script and my first C# code.  
>    
> I’ve been tasked with writing a PowerShell script to unzip a file and then change the filename. Unzipping the file works fine if I hardcode the filename:  
>    
> `function Extract-Zip { param([string]$zipfilename, [string] $destination) $shellApplication = new-object -com shell.application # $zipPackage = $shellApplication.NameSpace($zipfilename) $zipPackage = $shellApplication.NameSpace("C:\MyPath\SimpleZipname.zip") $destinationFolder = $shellApplication.NameSpace("C:\MyPath") $myfile = $destinationFolder.CopyHere($zipPackage.Items()) Write-Host $myfile } Extract-Zip "C:\MyPath\SimpleZipname.zip", "C] But if I try to use the same path passed in as a parameter, I get the error "You cannot call a method on a null-valued expression": function Extract-Zip { param([string]$zipfilename, [string] $destination) $shellApplication = new-object -com shell.application $zipPackage = $shellApplication.NameSpace($zipfilename) # $zipPackage = $shellApplication.NameSpace("C:\MyPath\SimpleZipname.zip") $destinationFolder = $shellApplication.NameSpace("C:\MyPath") $myfile = $destinationFolder.CopyHere($zipPackage.Items()) Write-Host $myfile } Extract-Zip "C:\MyPath\SimpleZipname.zip", "C] What am I doing wrong? I’m on Windows 7. This will eventually go on a Windows 2008 Server. Thanks, Greg`

by DonJ at 2012-11-09 10:13:35

> Lose the comma in your command. Parameters aren’t separated with commas.  
>   
> Extract-Zip -zipfilename c:\simplezipname.zip -destination c:\mypath

by GregL65 at 2012-11-11 09:46:20

> Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:02pm UTC](https://forums.powershell.org/t/my-first-powershell-script-also-my-first-c-code/322/2 "2024-05-16T21:02:36Z")

</div>


