I want to install an exe and this works for one pc but when I use get-content, it only picks up one pc.
My script isn’t probably indented correctly. Could anyone help me please? I’m still learning.
Hmmm … let’s see if I got everything right.
You do a lot of effort to create a variable $Profile which actually contains the username, right? A profile path without "c:\users" usually is the username.
Then you create another variable “$Username” which contains (if you’re lucky) one username (if there are more than one users on the computer you will get an array of usernames).
And in the end you run your executable locally with the parameters $Computer, $profile and $username
Probably something like this could work for you:
Hi Olaf, That’s the catch. The $profile isn’t the same as the $username. We changed the usernames in AD a while ago without renaming the C:\users\username folder. So we have the old username in here and what I’ve done is look at the newest profile in the C:\users folder and take that username, it’s worked so far. There’s probably a nicer way to do that?
The .exe file updates an .ini file in the C:\users\profilename folder.
I just have to combine $username and $profile in the script. Do you know how I’d add the $profile part into your suggested script above?
Hey Olaf, thanks for that. That worked great. Sorry to ask again but I probably should do some error logging. I’ve looked into try and catch and tried the following, am I on the right path?
And you could search for examples in the internet or read a book or see a tutorial. I think it will be a little too much to explain it here good enough.
But in your script - You have the “everything ran ok” in the try block. So it’s executed anyway - even if your executable fails. And that’s the next thing. Does your executable throws an error Powershell will be able to recognise/catch? … or is it maybe just an output to the “standard output” instead of the “standard error output”? So I’m not sure if this really works as you expect it to work. You could think about using “Start-Process”
At least IMHO the “positive” logging should not be in the try block.
Thanks for your help again. I think the last line of the script should have read “& ‘C:\temp\newphonenumber.exe’ $computer $profile $users” ? If I want to output what I have before I run the .exe, I could do something like this?