So I’m working my way up the ranks as being the only powershell “guru” at my firm and while I can usually knock out scripts fairly quickly, this one request has stumped me. I suspect it is because I’m not understanding how to store csv files into an array and being able to call them when needed. So here’s my scenario:
We are running Exchange 2013, migrating away from IBM Domino (save the laughter), and I have been asked to replicate a process in where we have a scheduled task that updates the out of office for users when they leave the firm; for various reasons. The process entails a manager inputting information into a web page with all the necessary information and clicks submit. That process is completed and I have a nice csv file saved onto a file share for my use.
I had originally asked for the list of mailboxes in one csv file because that’s what I’m used to, but there is a need to keep what was submitted for each person for historical reasons. So I took on the challenge to see what I can come up with.
The short of it is, I can get the list of csv files, but it will not process the information within the files. I’ve ensured that the csv contains the relevant header information. I aslo found that if I copy the files locally the script works. While I can add a move-item to get those files onto the local machine, I’m curious to know what I am doing wrong, as this will come in handy for future requests. Here’s what I have:
$CSVSourceDir = "uncpathtoshare" Get-ChildItem -path $CSVSourceDir -recurse -force | Where { $_.Name -like "*.csv" } | foreach-object {$filename=$_.userid;import-csv $filename | set-mailboxautoreplyconfiguration -identity $filename -autoreplystate Enabled -internalmessage $filename.internalmessage -externalmessage $filename.externalmessage -starttime $filename.startdate -endtime $filename.enddate -externalaudience All}
I had a conversation with a vbscript guy and he said it doesn’t look like I’m actually importing the values of the csv files in any way. Like I said before I had some snippets of code that tried using an array:
#for($i = 0;$i -le $csvarray.count -1;$i++){$csvarray[$i]}
Though I still couldn’t figure out how to grab the values I was looking for. Is there something I am missing that will allow me to grab those csv files from a remote share and be able to loop through each without having to bring them down to the local machine running the script?
Many thanks for any input.
Chuck