So, I posted earlier at https://www.reddit.com/r/PowerShell/comments/6caz4t/neophyte_powershell_user_seeking_a_small_bit_of/ and you guys offered a great bit of advice.
I’m running into another issue now, and it’s probably going to take me a while to explain it (as I said, I’m a neophyte, our company is understaffed and I’m trying to save our helpdesk SLA’s from plummeting).
So, We need to be able to have users automatically download a zip file to a directory on their local machine to register some software. This is hard for our users.
I’ve successfully made some code that DOES work (Nobody at my company has time to do this, I work the helpdesk and am trying to make a name for myself/help save our plummeting SLA’s), I’ve tested the script on several machines with different AD ID’s… here’s what it looks like:
$User = Read-Host -Prompt 'Enter your XXXID. Employees: Enter the CUID in lowercase. Contractors will use UPPERCASE' $c = Get-Credential Invoke-WebRequest -Uri "https://web.site.com/software/softwaredata_$User.zip" -OutFile "C:Program Files (x86)FolderFolder2softwaredata_$User.zip" -Credential $c cd “C:Program Files (x86)FolderFolder2” .software.exe "Now that the ZIP file has been placed in the appropriate directory, The software has now been loaded. Click REGISTER. Then simply populate the registry fields with the information contained in the registration e-mail" pause
The problem NOW is, our company’s execution policy is set to restricted by default. I’ve been looking for ways around this, and come across this line:
powershell.exe Set-ExecutionPolicy Bypass -Scope Process -Force
What I’d like to do is make a batch file that the user’s click on, it changes the execution policy, runs the script, downloads the file, and prompts them to register. No matter what I do, though, I can’t seem to make the batch file execute the script after changing the policy.
I’ve checked get-executionnpolicy and observed restricted, ran that simple bat and checked again and it was set to bypass. Now I just need it to run the script I made.
Is this possible? How I can I make the .bat file run the script I made after changing the execution policy to bypass? I know there’s a lot of other problems I’m going to have to encounter (error handling in the even the directory doesn’t exist, for example), but if I can just get this to work, it would show It’s possible and I’d get a great sense of accomplishment from it.
I’m coming to you guys as a last resort. i’ve googled, ran tests, and googled again. I just don’t know where to go from here. Can somebody provide advice?
WORTH NOTING: These user’s are on company-imaged workstations, provided with domain accounts. As internal helpdesk, I have admin privileges, but that is NOT an option I can grant any other users except for very special circumstances.
submitted by /u/theblueones
[link] [comments]
The post Neophyte again, seeking more help appeared first on How to Code .NET.