Hi
I’ve created a powershell function that requires the employeeID to collect all the data from that user.
now I want to call that function in a different powershell script passing on the required employeeID how do I do this? the function is called collect_data the filename is function_collect_data.ps1
these are the parameters of the function
I know that I can call the function collect_Data xxxxxx where the xxx is the employeeID and this works but if I call the specific function from a different file how would I pass the employeeID into my function?
I’m not completely sure what you’re actually asking. I’d recommend to either “outsource” this particular function to a separate file and call it from the different script needing this function by dot sourcing. Here you can read more about:
… or use an even more professional approach and create a module with this function. This way you could use
to make sure the needed modules are available for the script to run.
Regardless of that I’d highly recommend to use only approved verbs and the well known naming conventions of PowerShell to name your functions.
Functions usually return a PSObject, so in this use case, you might create a wrapper function to get specific properties for your company and do Get-CompanyAdUser, but it’s going to return the data. The Select-Object should be unnecessary, it is just recreating the PSObject returned from Get-ADUser with the same properties you returned from command. After you export the data, then you are re-importing the data (e.g. Import-Csv), but this is unnecessary because you have the data stored in the $reactivateme variable. The implementation would more like this (not tested):