Function ?? – HELP ! :)


I’ve written a short script which uses a function block to read the contents of CSV files, based on triggers. There is more to it but this is the point causing some pain! (:

The function is defined here:

Function InitialiseCount { $Count1 = [IO.File]::ReadAllText("\serversharefile1.csv") $Count2 = [IO.File]::ReadAllText("\serversharefile2.csv") $Count3 = [IO.File]::ReadAllText("\serversharefile3.csv") $Count4 = [IO.File]::ReadAllText("\serversharefile4.csv") } 

When running a single line of the statement, I get the exact result I want – an updated variable with the string from the CSV. eg:

$Count1 = [IO.File]::ReadAllText("\serversharefile1.csv") 

However when calling the function within my script, or by running it through the command pane in ISE, it seems to execute but doesn’t update the variable with a new value. I’ve added a start-sleep between lines to check the execution time increases, which it does.

This is the first time I’ve created a script with functions but I’ve included two more in this, with the other two working as intended. Undoubtedly it’s something simple that I’m missing – but I’m a bit stumped! 🙁

Any thoughts?

submitted by /u/Lovepump87
[link] [comments]

Leave a Reply