Newbie Expand-Archive Question

TL;DR How do I Expand-Archive to a non domain UNC folder with local admin login? I’ve reached info overload searching through the web and need an assist. Working in Powershell 5

So, I’ve been working with PS for 2 weeks now and I’m doing ok considering I have very little programming skills before hand. I’m hoping someone would be kind enough to throw me a bone for a little problem I’m having. It’s not complete so ignore the note I had made after the Expand-Archive. The gist of it is I need to take a file we download by FTP for each of our facilities in a zip file and unzip it to the facility backup at each location. The issue is the NAS boxes are not part of the domain so I need to have the script log into each box using the local admin account. If I open the //UNC path and login it’ll find the file and unzip it to the folder named after the time stamp.

I made the PSCredential correctly I believe, but the expand-archive doesn’t allow for the parameter and New-Item points me to use New-PSDrive to use $Credential. I used New-PSDrive even letting Powershell ISE walk me though building the command and IIRC it tells me the path was invalid. I feel like it’s something that will pop right out with someone who does this daily. I’m home so I can’t test right now, but my $Credintial, $user, $pword were set as global variables until I moved them inside the loop. Even so I had set the $fac to 27 so it would only do 1 loop for testing and I don’t think that was the issue.

#Hourly Backup from PCC to Facility local NAS

DO
{

for($fac=11; $fac -le 27){

$zipFile = Get-ChildItem -Path \\192.168.0.159\c$\SFTP_Process\"$($fac)emar"\downloads -Recurse | 
Select-Object -Last 1 
    

    $user = "$($fac)name\administrator"
    $pword = ConvertTo-SecureString -String "genericp@ssword" -AsPlainText -Force
    $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $pword


    
        #Timestamp for folder, and folder creation
        $TS = Get-date -Format g | foreach {$_-replace ":","."} | foreach {$_-replace "/","."}
        #New-Item -Path ("\\192.168", ($fac), "200\backup folder\" -Join ".") -Name "$TS" -itemtype "directory" -Credential $Credential
        $outpath = ("\\192.168", ($fac), "200\backup folder\$TS" -Join ".") 

              
            #Unzip
            Expand-Archive -Path \\192.168.0.159\c$\SFTP_Process\"$($fac)name"\downloads\$zipfile -DestinationPath $outpath
   
              



#Cleanup folders on backup older than the newest 3


#Cleanup old ZIP files in FTP folder



    $fac++


}
}while($fac -le 27)

#Reset fac to 11
$fac=11

Hey David,

Check out this solution.

I believe I saw that article, and I’ll give it a try tomorrow when I get to the office. I originally dismissed it because New-PSDrive or Get-PSDrive were used to replace that command in later versions to my understanding. Is the net use method considered best practice? This script is largely an exercise in learning for me so I’m trying to gather as much current info as I can. I’ve found a lot of PS 3 info on the internet, and even the material I can find on Amazon for example often deal with PS 3 and some 4. What I’ve found for PS 5 so far isn’t as abundant and I’m guessing that’s because backwards compatibility for scripts and down right breaking some older applications making it less common.