1

So I have a "Parent" Script, that does an invoke-command to some web servers, and inside of that invoke-command, I have a "Child" script that is removing and copying some files.

Here's the Parent script: (note: The $cred variable is a verified and functioning domain admin via securestring for now)

foreach ($server in $servers) {
    invoke-command -ComputerName $server -Credential $cred -ScriptBlock {
    & 'D:\Web\Deploy_CopyStaging2AppPools.ps1'
    }

For whatever reason, the child script seems to be getting permission errors (I think?)

The child script looks like this

$AppPoolDirs = @(
"SisterSitesCategory",
"SisterSitesManufacturer",
"TestimStopTrunk",
"1ss_bot2",
"1ss_test",
"1sspro",
"Canadabot2",
"DevelopBot2",
"hcbot2",
"LDEBOT2",
"LnBOT2"
)
#timestamp filter
filter timestamp {"$(Get-Date -Format o): $_"}
Write-Output "Starting AppPool Filecopies on $env:COMPUTERNAME" | Timestamp | Out-File -FilePath "D:\Web\Deploylog.txt" -Append

Foreach ($AppPoolDir in $AppPoolDirs) {
    Write-Output "The working AppPoolDirectory is $AppPoolDir"
    if
    (test-path D:\Web\AppPools\$AppPoolDir) {
        Write-Output "######APP POOL DIRECTORY FOUND#######! Gonna do stuff to the AppPoolDir $AppPoolDir"
        remove-item -path "D:\Web\AppPools\$AppPoolDir\bin\App_Web_*.dll" -WhatIf
        copy-item -path "\\1sl-den-web01\d$\web\staginglive\staging\*" -Destination "D:\Web\AppPools\$AppPoolDir" -recurse -Force -WhatIf
        }
    else {
        Write-Output "Directory $env:COMPUTERNAME D:\Web\AppPools\$AppPoolDir Doesn't exist, no removal or copying was done"
        }
    }

The remove-item works, the copy-item doesn't. Since the copy-item -path is on a remote machine, I'm guessing this is a permissions thing.

If it's a permissions thing, I'm guessing that the "Parent" script, while opening the invoke-command with the proper creds, isn't then calling the child script with proper creds?

Daniel Williams
  • 167
  • 1
  • 10

0 Answers0