Invoke-HKCUSettingsForAllUsers expanded use cases - Rename Function?

Since Invoke-HKCUSettingsForAllUsers just executes a scriptblock for every user profile fed into it, and since it references a $UserProfile object with properties NTAccount, SID, and ProfilePath, it can be used for much more than just setting registry keys. Off the top of my head I can think of using it with:
basically anything that you can put $UserProfile.ProfilePath into.
Since this all works just fine, can anyone think of any reason why this function should not be named something like Invoke-ScriptBlockForAllUsers? It allows one to do rather a lot more than just set registry values… Rather nice.

Does anyone have any interesting ways they’ve used this function?

Have you actually tried using that function with anything other than registry values? I looked at that function in the AppDeployToolkitMain.ps1 file and it only references registry info- reg.exe, ntuser.dat files, HKEY_Users etc. I tried using that function to copy a file today and I couldn’t get it to work… To copy or remove files or folders, you’d probably need to do something like this:

[string[]]$ProfilePaths = Get-UserProfiles | Select-Object -ExpandProperty ‘ProfilePath’
foreach ($ProfilePath in $ProfilePaths) {
Copy-File -Path “$dirFiles\discovery925_ug_en.pdf” -Destination “$ProfilePath\Desktop”

Yes. I’ve used it for other things. Since the $UserProfile object that it references contains the ‘NTAccount’,‘SID’,and ‘ProfilePath’ properties, anything you can use with those (mainly ‘ProfilePath’, I think) is fair game :wink:

Something like this works just fine:

<code>[scriptblock]$stuffToDo = {
   Copy-File -Path $PathToFile -Destination $($UserProfile.ProfilePath)\AppData\SomeFolder\
Invoke-HKCUSettingsForAllUsers -RegistrySettings $stuffToDo</code>

Since this is just a scriptblock that gets run ‘ForEvery’ user profile, and the $UserProfile object is set up internally, you can put anything you want in that scriptblock and it will get run once for every profile. Since the $UserProfile.ProfilePath property is already available then, anything that uses it will get the path of each user profile in turn.

Hmmm… Interesting… It does work! But it’s still loading/unloading the ntuser.dat for each user unnecessarily. I think I like my way better for copying/deleting files/folders… But I learned something… Thanks.

I realize that this is almost 2 years old, but I came to the forum because I was thinking the same thing. I’m thinking Invoke-ForEachUser is a much more fitting name.

I’m going to try to edit an XML file in each user’s profile.