Snapin issue - using powershell to copy items
-
Hello @rodluz
I made the changes (see below) It runs like expected when run FROM the machine; however, when running through FOG it still says running, then immediately completed, and nothing is copied. Ideas here? Log just shows completed. But the folder is empty
cls
$username = “starshipfrontier\wbadmin”
$password = ConvertTo-SecureString “USSWhiteBuffalo33247” -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential $username, $password
$NetworkPath = “\starbase\Artemis_Files\Artemis Versions\Mod\Artemis 2.8 TNG Mod”
$LocalPath = “C:\Artemis 2.8 TNG Mod”#New-PSDrive -Name Artemis -PSProvider FileSystem -Root “\starbase\Artemis_Files\Artemis Versions\Mod\Artemis 2.8 TNG Mod” -Credential $creds
New-PSDrive -Name “S” -Root $NetworkPath -PSProvider “FileSystem” -Credential $cred
#Get-PSDrive -Name “S”RUN YOUR CODE REFERENCING THE “Z” DRIVE
Write-Host “Copying Artemis to Local Computer” -ForegroundColor DarkCyan
if(Test-Path $LocalPath) {“Temp folder found”} else {New-Item -ItemType Directory -Force -Path $LocalPath}
New-Item -ItemType Directory -Force -Path $LocalPath
Copy-Item S:* -Destination $LocalPath -Recurse -ForceWrite-Host “Copy Complete” -ForegroundColor DarkCyan
Remove-PSDrive -Name “S” -
@dellborg82 You seem to have a typo, that or because it’s not in code format (triple back ticks) we’re losing context.
Your script should be:
$NetworkPath = "\\starbase\Artemis_Files\Artemis Versions\Mod\Artemis 2.8 TNG Mod"
$LocalPath = "C:\Artemis 2.8 TNG Mod"
$username = "starshipfrontier\wbadmin"
$password = ConvertTo-SecureString "USSWhiteBuffalo33247" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential $username, $password
New-PSDrive -Name "S" -Root $NetworkPath -PSProvider "FileSystem" -Credential $cred
If (-Not (Test-Path $LocalPath)) {
Write-Host "Creating $LocalPath" -ForegroundColor DarkCyan
New-Item -ItemType Directory -Force $LocalPath
}
Write-Host "Copying Artemis to Local Computer" -ForegroundColor DarkCyan
Copy-Item S:\* -Destination $LocalPath -Recurse -Force
Write-Host "Copy Complete" -ForegroundColor DarkCyan
Remove-PSDrive -Name "S"
Why it’s not showing the full appropriately lined strings I don’t know.
-
Hello @Tom-Elliott, Thanks for your help here; however, it’s still not working and when I run it locally, I get the below error on New-PSDrive
I’m not the best at PowerShell, but have been learning here and there.
Please Advise where this may be going wrong. Unless I’m Mistaken (and I likely am) is this being caused by the $credIf (-Not (Test-Path $LocalPath)) part of the script?
-
@dellborg82 I printed the actual code as an image in my post because for some reason the code syntax is joining lines in appropriately here.
-
@Tom-Elliott Thanks for clarifying that.
I’m not sure why I didn’t catch that. Trying now. (It ran locally, just fine); however, run run via FOG, The pop up comes up that says it’s running, 3 seconds later, popup shows it’s complete (this is what we’ve been seeing)
I check the folder… empty
-
@dellborg82 Can you look at the event logs and see if anything shows up for that timeframe that the script actually runs.
-
@Tom-Elliott Here’s the log file from C:\fog.txt. As far as I can tell, (again I could be wrong) but it looks like the log shows it’s running.
8/16/2023 5:14:14 PM Client-Info Client Version: 0.13.0
8/16/2023 5:14:14 PM Client-Info Client OS: Windows
8/16/2023 5:14:14 PM Client-Info Server Version: 1.5.10.10
8/16/2023 5:14:14 PM Middleware::Response Success
8/16/2023 5:14:14 PM SnapinClient Running snapin Copy Current Artemis
8/16/2023 5:14:14 PM Middleware::Communication Download: https://10.4.47.15/fog/service/snapins.file.php?mac=5C:51:4F:AB:0E:92|5E:51:4F:AB:0E:91|18:A9:9B:FD:A2:71|5C:51:4F:AB:0E:91|5C:51:4F:AB:0E:95&taskid=178
8/16/2023 5:14:15 PM SnapinClient C:\Program Files (x86)\FOG\tmp\Copy_Current_Artemis_V3.ps1
8/16/2023 5:14:15 PM Bus Emmiting message on channel: Notification
8/16/2023 5:14:15 PM SnapinClient Starting snapin
8/16/2023 5:14:18 PM SnapinClient Snapin finished
8/16/2023 5:14:18 PM SnapinClient Return Code: 0
8/16/2023 5:14:18 PM Bus Emmiting message on channel: Notification
8/16/2023 5:14:18 PM Middleware::Communication URL: https://10.4.47.15/fog/service/snapins.checkin.php?taskid=178&exitcode=0&mac=5C:51:4F:AB:0E:92|5E:51:4F:AB:0E:91|18:A9:9B:FD:A2:71|5C:51:4F:AB:0E:91|5C:51:4F:AB:0E:95&newService&jsonBut still nothing in the C:\Artemis 2.8 TNG Mod Directory. The directory gets created, but it’s empty.
-
Is this what you were looking for?
-
@dellborg82 @Tom-Elliott Thanks for your help here, I was able to figure out the issue with your guidance. I’m not 5/5 on successful copies via PowerShell.
-
@dellborg82 What was the issue? This way somebody else who may be having a similar issue can also be helped?