Hi,<\/p>\n
I’m trying to install a .msi file which seems to be being hard work. Deploying it by broup policy and a startup script won’t work but I’ve found running it from powershell as administrator does work.<\/p>\n
I tried to create a skip that will connect onto a list of PCs and run the install. The script starts but once the Enter-PSSession line runs, it just brings up the remote session and pauses, it doesn’t continue to run the rest of the script. If I manually enter the next lines it will run the install succesfully, delete the file and stop the service but it then doesn’t run through the loop.<\/p>\n
$logfile = \"C:\\Scripts\\Deploy.txt\"\n$cred = Get-Credential domain\\Administrator\nforeach($pc in (Get-content C:\\Scripts\\computers.txt)){\nwrite-verbose \"Working on $pc\" -Verbose\n if(Test-Path \"\\\\$pc\\c$\"){\n Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Running\n Copy-Item \"\\\\Server\\FileShare\\file.msi\" \\\\$pc\\c$\\WINDOWS\\Temp\\\n Enter-PSSession –ComputerName $pc –Credential $cred\n msiexec.exe /i \"C:\\WINDOWS\\Temp\\file.msi\" /qn /log \"C:\\Windows\\Temp\\InstallLog.txt\"\n exit\n Remove-Item \"\\\\$pc\\c$\\WINDOWS\\Temp\\file.msi\"\n Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Stopped\n }else{Add-content $Logfile -value $pc}\n}\n<\/code><\/pre>\nDoes anyone have any pointers?<\/p>","upvoteCount":3,"answerCount":9,"datePublished":"2021-02-11T13:56:26.000Z","author":{"@type":"Person","name":"tomgudzelak1102","url":"https://community.spiceworks.com/u/tomgudzelak1102"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi,<\/p>\n
I’m trying to install a .msi file which seems to be being hard work. Deploying it by broup policy and a startup script won’t work but I’ve found running it from powershell as administrator does work.<\/p>\n
I tried to create a skip that will connect onto a list of PCs and run the install. The script starts but once the Enter-PSSession line runs, it just brings up the remote session and pauses, it doesn’t continue to run the rest of the script. If I manually enter the next lines it will run the install succesfully, delete the file and stop the service but it then doesn’t run through the loop.<\/p>\n
$logfile = \"C:\\Scripts\\Deploy.txt\"\n$cred = Get-Credential domain\\Administrator\nforeach($pc in (Get-content C:\\Scripts\\computers.txt)){\nwrite-verbose \"Working on $pc\" -Verbose\n if(Test-Path \"\\\\$pc\\c$\"){\n Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Running\n Copy-Item \"\\\\Server\\FileShare\\file.msi\" \\\\$pc\\c$\\WINDOWS\\Temp\\\n Enter-PSSession –ComputerName $pc –Credential $cred\n msiexec.exe /i \"C:\\WINDOWS\\Temp\\file.msi\" /qn /log \"C:\\Windows\\Temp\\InstallLog.txt\"\n exit\n Remove-Item \"\\\\$pc\\c$\\WINDOWS\\Temp\\file.msi\"\n Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Stopped\n }else{Add-content $Logfile -value $pc}\n}\n<\/code><\/pre>\nDoes anyone have any pointers?<\/p>","upvoteCount":3,"datePublished":"2021-02-11T13:56:26.000Z","url":"https://community.spiceworks.com/t/enter-pssession-within-script-pauses-in-new-session/790393/1","author":{"@type":"Person","name":"tomgudzelak1102","url":"https://community.spiceworks.com/u/tomgudzelak1102"}},{"@type":"Answer","text":"
What you describe seems to be “expected” due to the way enter-pssession works.<\/p>\n
What if you replace “enter-pssession” with “invoke-command”? That should do what you want.<\/p>","upvoteCount":1,"datePublished":"2021-02-11T14:05:33.000Z","url":"https://community.spiceworks.com/t/enter-pssession-within-script-pauses-in-new-session/790393/2","author":{"@type":"Person","name":"Carl-Holzhauer","url":"https://community.spiceworks.com/u/Carl-Holzhauer"}},{"@type":"Answer","text":"
Is it getting stuck on waiting for Execution policy override?<\/p>","upvoteCount":0,"datePublished":"2021-02-11T14:07:18.000Z","url":"https://community.spiceworks.com/t/enter-pssession-within-script-pauses-in-new-session/790393/3","author":{"@type":"Person","name":"eric7615","url":"https://community.spiceworks.com/u/eric7615"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>