OK, this is either weird or I’m blind/doing something stupid. I’m creating an array of filenames using Get-ChildItem, and the array is being created, I’ve written it to the console to make sure; however, when I try to pull a file from the list using ForEach, the filename is blank. Is something wrong here, or am I as dumb as I’m starting to feel? I’ve been chasing this for over two days now. I know it’s a bit long, but I’m posting the entire script because I’m using inter-dependent functions.<\/p>\n
Function Install-Downloads\n{\n $script:MSIFiles = Get-ChildItem -Path $TargetDir -Name '*.msi' -File\n \n #Inserted for logging to make sure the array(s) are created.\n Write-HostLog \"`n`rMSIFiles\"\n $MSIFiles | Format-Table -AutoSize\n \n $script:EXEFiles = Get-ChildItem -Path $TargetDir -Name '*.exe' -File\n \n Write-HostLog \"`n`r$EXEFiles\"\n $ExeFiles | Format-Table -AutoSize\n\n#Start processing downloads.\n Try\n {\n if ($MSIFiles = '')\n {\n Write-HostLog \"`n`rNo MSI files downloaded. Skipping...`n`r\"\n }\n else\n {\n Write-HostLog \"`n`rProcessing MSI files...`n`r\"\n foreach ($File in $MSIFiles) \n {\n $MSIArguments = @(\n '/i',\n \"$File\"\n '/qn',\n '/norestart'\n )\n \n#This is the first sign something's wrong. $File is blank.\n Write-HostLog \"`n`rMSI = $File\"\n Write-HostLog \"`n`rProcessing $File ...\"\n Start-Process -FilePath $env:systemroot\\system32\\msiexec.exe -ArgumentList $MSIArguments -PassThru -Verb runas -Wait\n }\n }\n }\n \n Catch\n {\n Write-HostLog \"`n`rError processing file $File. See $ErrorLogFullPath for details.`n`r\"\n $Line = Write-Line\n Write-ErrorLog \"`n`r$Line\" -LogFile $ErrorLogFullPath\n $LineNumber = Get-CurrentLine\n Write-ErrorLog $LineNumber -LogFile $ErrorLogFullPath\n Write-ErrorLog \"Exception Type: $($_.Exception.GetType().FullName)\" -LogFile $ErrorLogFullPath\n Write-ErrorLog \"Exception Message: $($_.Exception.Message)\" -LogFile $ErrorLogFullPath\n }\n \n Finally\n {\n Write-HostLog \"`n`rMSI installation is now complete!`n`r\"\n } \n}\n\n<\/code><\/pre>\n
Advertisement
This is the transcript log file.<\/p>\n
**********************\nHost Application: C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\PowerShell_ISE.exe\nPSVersion: 5.1.14393.206\nPSEdition: Desktop\nPSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.206\nBuildVersion: 10.0.14393.206\nCLRVersion: 4.0.30319.42000\nWSManStackVersion: 3.0\nPSRemotingProtocolVersion: 2.3\nSerializationVersion: 1.1.0.1\n**********************\nTranscript started, output file is C:\\Logs\\SpecialLogs\\AR_Test9\\\\AR_Test9-Log_2017.09.26-14.15.30.log\n...\n\nMSIFiles\nExternalDiskCache_amd64_en-US.msi\nrequestRouter_amd64.msi\nrewrite_amd64_en-US.msi\nWebDeploy_amd64_cs-CZ.msi\nWebFarm2_x64.msi\nWebPlatformInstaller_amd64_en-US.msi\n\nProcessing MSI files...\n\nMSI =\n\nProcessing ...\nPS C:\\WINDOWS\\system32> TerminatingError(Start-Process): \"Cannot validate argument on parameter 'ArgumentList'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.\"\n\nError processing file . See C:\\Logs\\SpecialLogs\\ARR_Test11\\\\ARR_Test11-ErrorLog_2017.09.26-14.50.31.log for details.\n\nMSI installation is now complete!\n\nThere were errors encountered during script execution. Please see C:\\Logs\\SpecialLogs\\ARR_Test11\\\\ARR_Test11-ErrorLog_2017.09.26-14.50.31.log for details.\n**********************\n\n<\/code><\/pre>\n
Advertisement
@martin9700<\/a> @thomaslee<\/a><\/p>","upvoteCount":2,"answerCount":22,"datePublished":"2017-09-26T16:28:47.000Z","author":{"@type":"Person","name":"s31064","url":"https://community.spiceworks.com/u/s31064"},"acceptedAnswer":{"@type":"Answer","text":"Look at line 402 (by my count) in the Try block. You have equal sign (=) for a condition statement instead of -eq. The equal sign assigns a value s instead of comparing values.<\/p>\n
Try\n {\n if ($MSIFiles = '')\n {\n Write-HostLog \"`n`rNo MSI files downloaded. Skipping...`n`r\"\n }\n...\n<\/code><\/pre>\nInstead, it should be something like this:<\/p>\n
Try\n {\n if ($MSIFiles.Count -eq 0)\n {\n Write-HostLog \"`n`rNo MSI files downloaded. Skipping...`n`r\"\n }\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2017-09-26T17:17:14.000Z","url":"https://community.spiceworks.com/t/where-are-my-filenames-going/608411/5","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},"suggestedAnswer":[{"@type":"Answer","text":"OK, this is either weird or I’m blind/doing something stupid. I’m creating an array of filenames using Get-ChildItem, and the array is being created, I’ve written it to the console to make sure; however, when I try to pull a file from the list using ForEach, the filename is blank. Is something wrong here, or am I as dumb as I’m starting to feel? I’ve been chasing this for over two days now. I know it’s a bit long, but I’m posting the entire script because I’m using inter-dependent functions.<\/p>\n
Function Install-Downloads\n{\n $script:MSIFiles = Get-ChildItem -Path $TargetDir -Name '*.msi' -File\n \n #Inserted for logging to make sure the array(s) are created.\n Write-HostLog \"`n`rMSIFiles\"\n $MSIFiles | Format-Table -AutoSize\n \n $script:EXEFiles = Get-ChildItem -Path $TargetDir -Name '*.exe' -File\n \n Write-HostLog \"`n`r$EXEFiles\"\n $ExeFiles | Format-Table -AutoSize\n\n#Start processing downloads.\n Try\n {\n if ($MSIFiles = '')\n {\n Write-HostLog \"`n`rNo MSI files downloaded. Skipping...`n`r\"\n }\n else\n {\n Write-HostLog \"`n`rProcessing MSI files...`n`r\"\n foreach ($File in $MSIFiles) \n {\n $MSIArguments = @(\n '/i',\n \"$File\"\n '/qn',\n '/norestart'\n )\n \n#This is the first sign something's wrong. $File is blank.\n Write-HostLog \"`n`rMSI = $File\"\n Write-HostLog \"`n`rProcessing $File ...\"\n Start-Process -FilePath $env:systemroot\\system32\\msiexec.exe -ArgumentList $MSIArguments -PassThru -Verb runas -Wait\n }\n }\n }\n \n Catch\n {\n Write-HostLog \"`n`rError processing file $File. See $ErrorLogFullPath for details.`n`r\"\n $Line = Write-Line\n Write-ErrorLog \"`n`r$Line\" -LogFile $ErrorLogFullPath\n $LineNumber = Get-CurrentLine\n Write-ErrorLog $LineNumber -LogFile $ErrorLogFullPath\n Write-ErrorLog \"Exception Type: $($_.Exception.GetType().FullName)\" -LogFile $ErrorLogFullPath\n Write-ErrorLog \"Exception Message: $($_.Exception.Message)\" -LogFile $ErrorLogFullPath\n }\n \n Finally\n {\n Write-HostLog \"`n`rMSI installation is now complete!`n`r\"\n } \n}\n\n<\/code><\/pre>\nThis is the transcript log file.<\/p>\n
**********************\nHost Application: C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\PowerShell_ISE.exe\nPSVersion: 5.1.14393.206\nPSEdition: Desktop\nPSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.206\nBuildVersion: 10.0.14393.206\nCLRVersion: 4.0.30319.42000\nWSManStackVersion: 3.0\nPSRemotingProtocolVersion: 2.3\nSerializationVersion: 1.1.0.1\n**********************\nTranscript started, output file is C:\\Logs\\SpecialLogs\\AR_Test9\\\\AR_Test9-Log_2017.09.26-14.15.30.log\n...\n\nMSIFiles\nExternalDiskCache_amd64_en-US.msi\nrequestRouter_amd64.msi\nrewrite_amd64_en-US.msi\nWebDeploy_amd64_cs-CZ.msi\nWebFarm2_x64.msi\nWebPlatformInstaller_amd64_en-US.msi\n\nProcessing MSI files...\n\nMSI =\n\nProcessing ...\nPS C:\\WINDOWS\\system32> TerminatingError(Start-Process): \"Cannot validate argument on parameter 'ArgumentList'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.\"\n\nError processing file . See C:\\Logs\\SpecialLogs\\ARR_Test11\\\\ARR_Test11-ErrorLog_2017.09.26-14.50.31.log for details.\n\nMSI installation is now complete!\n\nThere were errors encountered during script execution. Please see C:\\Logs\\SpecialLogs\\ARR_Test11\\\\ARR_Test11-ErrorLog_2017.09.26-14.50.31.log for details.\n**********************\n\n<\/code><\/pre>\n@martin9700<\/a> @thomaslee<\/a><\/p>","upvoteCount":2,"datePublished":"2017-09-26T16:28:48.000Z","url":"https://community.spiceworks.com/t/where-are-my-filenames-going/608411/1","author":{"@type":"Person","name":"s31064","url":"https://community.spiceworks.com/u/s31064"}},{"@type":"Answer","text":"Can you maybe please just post the few lines that you think are causing the issue?
\nI mean you just posted about 500 lines of code…<\/p>","upvoteCount":1,"datePublished":"2017-09-26T16:33:40.000Z","url":"https://community.spiceworks.com/t/where-are-my-filenames-going/608411/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"