I think you should test with a simple script first like:
write-output "Hello world"
If that works please let us know which line fails in yoru script.
I have other scripts that are still working. There is no single line that is failing. The execution completes indicating it completed successfully, but it didn't. The output csv file from these scripts are all blank. The output csv files from the other scripts are working fine. When I run each of the scripts that is outputting a blank file when run with VCron manually with powershell ISE they are outputting the csv as expected.
Example script that works and completes with expected output:$guid = [guid]::NewGuid()
$json = [ordered]@{
schema = "com.domain.maxis.job.export:2014-05-01"
type = "documentSearch"
authorizations = @([ordered] @{
id = "$guid"
effect = "ALLOW"
action = "CAN_READ"
principal = "kerberos:jppulley@DOMAIN.COM"
resource = "this"
})
parameters = [ordered] @{
search = [ordered] @{
schemaType = "com.domain.maxis.issue"
q = "containingFolder:49f2f05f-611e-44d9-a5aa-e049b2ab85c6"
sort = "lastUpdatedConversationDate desc"
}
exportData = [ordered] @{
type = "table"
columns = @(
@{columnId = "assignedfolderid"},
@{columnId = "issueid"},
@{columnId = "title"},
@{columnId = "shortid"},
@{columnId ="status"},
@{columnId = "nextstepaction"},
@{columnId = "assignedfolderlabel"},
@{columnId = "labels"},
@{columnId = "requesteridentity"},
@{columnId = "createdate"},
@{columnId = "lastupdateddate"},
@{columnId = "lastresolveddate"},
@{columnId = "assigneeidentity"},
@{columnId = "prioritylevel"},
@{columnId = "rank"},
@{columnId = "planningestimate"},
@{columnId = "estimatedstartdate"},
@{columnId = "estimatedcompletiondate"},
@{columnId = "actualstartdate"},
@{columnId = "actualcompletiondate"},
@{columnId = "needbydate"},
@{columnId = "issueurl"},
@{columnId = "submitteridentity"},
@{columnId = "resolvedbyidentity"},
[ordered] @{path = "/customFields/string/targeted_release_date_if_salesforce/value"
outputFieldName="targeted_release_date_of_salesforce"},
[ordered] @{path = "/customFields/string/request_type/value"
outputFieldName="SDS_SIM_Request_Type"},
[ordered] @{path = "/customFields/string/progress_status/value"
outputFieldName="SDS_SIM_Progress_Status"},
[ordered] @{path = "/customFields/string/risk_color_status/value"
outputFieldName="SDS_SIM_Request_Color_Status"},
[ordered] @{path = "/customFields/string/path_back_to_green/value"
outputFieldName="SDS_SIM_Path_Back_to_Green"})
}
exportFiles = @([ordered] @{
id="csv"
format="csv"}
)
exportContent = @{
type="issues"
}
}
} | ConvertTo-Json -Depth 6
# Get a SIM Session Cookie
Invoke-WebRequest -UseDefaultCredentials -UseBasicParsing -Uri
https://maxis-service-prod.domain.com/users/whoami -SessionVariable sim
#Send Post to Create Job
$response = Invoke-RestMethod -UseDefaultCredentials -UseBasicParsing -WebSession $sim -Uri
https://maxis-service-prod.domain.com/jobs -Method Post -Body $json -ContentType "application/json"
#store the document ID for job retrieval
$documentID = $response.id
#Loop until the job is completed
do {
$checkstatus = Invoke-RestMethod -UseDefaultCredentials -UseBasicParsing -WebSession $sim -Uri
https://maxis-service-prod.domain.com/jobs/ $documentID
Start-Sleep -S 10
if ($checkstatus.status -eq "Failed"){
break
}
} until ($checkstatus.status -eq "Complete")
#get attachments json section
$attachment = $checkstatus.attachments
#get ID for the attachment
$attachmentID = $attachment.id
#set Document Retrieval URL
$docDownload = 'https://maxis-service-prod.domain.com/jobs/'+$documentID+'/attachments/'+$attachmentID
#set the save file location
$savefileTarget = '\\domain\dept\dcgsi\Extracts\SIM_SDS_Issues.csv'
if (Test-Path $savefileTarget) {
Remove-Item $savefileTarget
}
#Get the csv file
if ($checkstatus.status -eq "Complete") {
Invoke-WebRequest -UseDefaultCredentials -UseBasicParsing -WebSession $sim -Uri $docDownload -OutFile $savefileTarget
}else{
Set-Content -Path "\\domain\dept\dcgsi\Extracts\SIM_SDS_errors.txt" -Value $checkstatus.Content -Force
}
Example of script that says it completes successfully (and does work when manually run) but outputs a blank file:$uri = 'https://playbook2somain.com/data/folder/export/24125'
$of = '\\domain\dept\DCGSI\Extracts\DCCD Projects.xlsx'
$sf = '\\domain\dept\DCGSI\Extracts\DCCD Modified.csv'
function Get-Data {
wget $uri -outfile $of -UseDefaultCredentials
}
function CSV-Creation {
if (Test-Path $sf) {
Remove-Item $sf
}
$excel = New-Object -ComObject "Excel.Application"
$Workbook = $excel.Workbooks.Open($of)
$page = 'Project Summary'
$ws = $Workbook.worksheets | where-object {$_.Name -eq $page}
Start-Sleep 5
$cells=$ws.Cells
$range = $ws.UsedRange
$rows = $range.Rows.Count
$dataDate = (Get-Date).tostring("yyyy-MM-dd")
$cols = $range.Columns.Count
$newCol = $cols + 1
$ws.Cells(1, $newCol).Value = "Snapshot"
for($i = 2; $i -ne $rows+1; $i++){
$ws.Cells($i, $newCol).Value="$dataDate"
$ws.Cells($i, $newCol).NumberFormat="yyyy-mm-dd"
}
$excel.visible = $true
$excel.DisplayAlerts = $false
$excel.ActiveWorkbook.SaveAs('\\domain\dept\DCGSI\Extracts\DCCD Modified.csv',6)
Close-Excel
}
function Close-Excel {
Start-Sleep 1
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($ws)|out-null
$ws=$null
Start-Sleep 1
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($Workbook)|out-null
$Workbook=$null
Start-Sleep 1
$excel.Quit()
Start-Sleep 1
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)|out-null
$excel=$null
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
}
function Clean-Dates {
(Get-Content $sf) | Foreach-Object {$_ -replace '(\d{1,2})/(\d{1,2})/(\d{4})', '$3-$1-$2' } | Set-Content $sf
}
function Clean-Downloads {
Remove-Item $of
}
Get-Data
CSV-Creation
Clean-Dates
Clean-Downloads
Keep in mind that prior to 8.3.4 both of these scripts worked. Now the second one is outputting a blank file when executed through visual cron, but not when executed via powershell ISE or powershell.