I know this may sound like a question that was here before (and partially it will be true). Yet i have an interesting twist here.
Needed flow:
run Powershell script from CMD.
Seems trivial, and is actually working, with passing parameters etc...
But ...
My powershell script has a Start-Job with in it, as i want it to run async.
#######################################################################
#$DropLocation = "SOME UNC PATH"
#$buildid = "SOME VERSION"
param (
[parameter(Mandatory = $true)][string]$DropLocation,
[parameter(Mandatory = $true)][string]$buildid
)
Start-Job -Name Upload `
-ScriptBlock {
param (
[parameter(Mandatory = $true)][string]$DropLocation,
[parameter(Mandatory = $true)][string]$buildid
)
Write-Output "asd"
$buildpath = $DropLocation+"\"+$buildid
$logs = gci $buildpath"\logs" -Name "ActivityLog.AgentScope*.xml"
#Start-Sleep -Seconds 300
if ($logs.PSPath -gt 0)
{
$destination = $env:TEMP+"\Config\"
Copy-Item $logs.PSPath "$destination $buildid.xml"
}
} `
-ArgumentList $DropLocation,$buildid
#######################################################################
I am using Param to intake from outside, and then once again in the Start-Job so that the Async job get its params
This script is saved as SCRIPTNAME.ps1 and i am trying to run it from CMD.
From cmd (running as admin)
powershell "& "C:\temp\SCRIPTNAME.ps1" "SOME UNC PATH" "SOME VERSION""
or
powershell -file "C:\temp\SCRIPTNAME.ps1" "SOME UNC PATH" "SOME VERSION"
Nothing happens.
Yet from the PowerShell ISE all is working well
Assistance is more than appreciated!
cd C:\location of ps.1and running.\thefile.ps1?"in the first command as\". The second command looks correct (and is the better choice). When you say that nothing happens, can you be more specific? No error message? Is the script invoked at all?