Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Calling one PowerShell Script from Another

$
0
0

Hi,

I am trying to write a PowerShell script that will call another PowerShell script when the first one finishes. Can't get it to work.

1. First script downloads some folders and files from a network share to the users' local C: Drive

2. When the files have finished copying, then fire off another PowerShell script that is part of the files that were copied to the local computer.

    

# Specify the source and destination paths
$Source = "\\SERVER\SHARE$\PSAPPDEPLOY\"
$Destination = "C:\PSAPPDEPLOY"

# Check if the folder exists and if not create it and copy the PSAppDeploymentKit files to the local C: Drive

If (!(Test-Path $Destination)) {

   Copy-Item -Path $Source -Destination $Destination -Recurse

}

Else {
   Write-Host "Directory already exists!"
   Exit
}

$scriptpath = C:\PSAPPDEPLOY\Deploy-Application.ps1

$ArgumentList = -DeploymentType Install - DeployMode Interactive

Invoke-Expression"$scriptPath $argumentList"

Also, is there a way to bypass UAC and get these to fire off without the prompt? I see a way to do it via a batch file, but was hoping to use PowerShell for the whole thing.

Here's a batch file example:

@ECHO OFF
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\PSAPPDEPLOY\Deploy-Application.ps1""' -Verb RunAs}"
PAUSE



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>