I created a module for my administration group with some functions that automate some of the procedures that we usually perform (add administrators to the remote computers, erase the C drive, etc.)
One of the prerequisites for these functions is the generation of a series of 7 credentials, one for each domain in which we operate.
Is there a way to run the script block when importing a module, or is this what I should add to each person’s profile?
The comments mention that I can just add it to the module.psm1 file, but that didn't work. Here is the code I'm trying to run.
$creds = Import-Csv [csvfile]
$key = Get-Content [keyfile]
foreach ($cred in $creds) {
$user = $cred.User
$password = $cred.Hash | ConvertTo-SecureString -Key $key
$i = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password
New-Variable -Name ($cred.Domain + "_Cred") -Value $i -Force
}
Running this manually does work fine, but it does not create credentials when run from the Import-Module command.