Azure Devops Interactive agent - powershell

For running our UI tests were using the task "Visual Studio test agent deployment", which has been deprecated now. So i have moved the tasks to use "Visual Studio Test" task.
This needs agents to be configured as interactive process rather than service. So i created a new build server with interactive process agent running with admin rights user.
For signing or code we are using signed certificates that gets installed on the build server. But for some reason this new build server seems to loose the certificate cred every single time the pipeline runs.
I have tried to to run a ps1 file to reinstall the cert with no success. Below id the code that i have for reinstalling the cert and i am using task "PowerShell on target machines" to run the script. The user running this script is admin on the box, is there a different way of getting the ps1 file to run as admin all the time?
Set-Location "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools"
Start-Process cmd.exe
Sleep 2
$WshShell = New-Object -ComObject WScript.Shell
Sleep 2
$WshShell.sendkeys(".\sn.exe -d $KeyContainer{Enter}");
Sleep 2
$WshShell.sendkeys(".\sn.exe -i $PfxCertificatePath $KeyContainer{Enter}");
Sleep 2;
$WshShell.sendkeys("$passWord{Enter}");
Sleep 2;
$WshShell.sendkeys("{Enter}");
Any help would be greatly appreciated.

Is there a way to get the cmd.exe to run as admin through the
pipeline?
As i know, for now only the version 3.0 of Powershell on Target Machine task supports our running it as admin. Apart from it, the Command-line task and PowerShell Task doesn't support this feature yet.
So I'm afraid the answer is negative, Azure Devops pipeline doesn't have the option to make us run those tasks(CMD task, PS task...) with admin rights. (According to your description, you're trying to get a different way of using PS on Target Machine task. )
Sorry for the inconvenience. Actually I think it could be one good idea so you could feel free to add your request(CMD task with admin...) for this feature on our UserVoice site, which is our main forum for product suggestions. But it may not be accepted by MS if it doesn't get enough votes.
Hope it helps:)

Related

Powershell command works manually, but does not work when executed in Jenkins

I'm having a strange scenario where my command works on PowerShell manually but not when executed on Jenkins PowerShell plugin. I'm new to PowerShell and Jenkins and I'm thinking that there's a rule I'm missing. I looked all over the here and net but I failed to find the solution.
I created a job that executes a PowerShell script that opens an RDP file on my desktop using a freestyle project. It works as expected when executed on Powershell but in Jenkins, the build succeeds but it did not open the RDP.
Here's the script:
Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "RDP File /h:900 /w:1600" -WindowStyle Minimized
I'm using Windows Server 2016.
Here's what I tried:
By default Jenkins uses 32-bit PowerShell, so I manually used the 64-bit but it didn't work.
I made sure that Get-ExecutionPolicy is set to RemoteSigned on LocalMachine
Run the script using Windows Batch Command
I tried opening notepad but it does not work too.
Is this really the behavior of the PowerShell plugin? Is there any points that I'm missing? Kindly help me with this.
To anyone might need this. I was able to execute the RDP via Jenkins PowerShell plugin.
What I did was to go Jenkins' Window Service > Log on tab > Select "This account" and enter your user account credentials.
I suspect this is a security issue. Jenkins by default is using the "SYSTEM" account which does not have enough privileges.

SCCM Powershell Script Package

I have created a package in SCCM 2012 that should deploy and run a powershell script. I have looked at a previous post on here Other Post but there wasn't any information.
In the Program Command Line, I have the following command:
powershell.exe -ExecutionPolicy Bypass -force -WindowStyle Hidden .\PowershellUpdateScript.ps1
I am targeting a test group and setting it to deploy immediately however when I check the deployment status, it shows as status "In Progress" and Description "Received". It has been that way for over 2 hours. I am not sure where the issue is.
I know that the Scripts feature is there and super convenient but the client powershell version needs to be a minimum version 3. The irony is that this package will update client powershell versions.
Any suggestions or advise would be greatly appreciated.
Since you are updating the powershell version, instead of using a powershell script you should download the MS update package for the version of powershell.
You can then use the wusa.exe command to deploy the update. Then use this ps command as a detection method
Get-WmiObject Win32_QuickFixEngineering -filter "HotFixID='KB#######'"

TFS Run PowerShell on Targe Machines not working?

I'm Running powershell script using TFS build step - Run PowerShell on Target Machines but it does not work.
Here's how script looks like:
Start-Process -FilePath 'Bginfo.lnk'
It runs shurtcut that refreshes information on pc desktop using bginfo.exe - script works fine when its executed manualy.
TFS executes that script, but it does not work - bginfo is not refreshed.
If I add to that script line that creates new file it also will be created.
Why it does not automatically update background using specified shurtcut?
I can reproduce this issue. Tried command line, batch script, PowerShell steps with /TIMER:0 /SILENT /NOLICPROMPT set and with the service account which has administrator's privilege. Seems it only works when run the script manually on target machine.
In this case, if you want to refresh the system info automatically, you can use task schedule to run the Bginfo script in target machine. Reference below threads :
BGinfo not running silently
BGInfo on Windows Server 2012
Making BgInfo work in Windows 2012 / Windows 2016

How can I make octopus deployment step execute as administrator in order to call Update-SPSolution

I have setup an Octopus deployment script to update SharePoint solutions using Update-SPSolution and WSP packages.
When I test the script from Powershell ISE (run as Administrator), it works.
When I test the script from Powershell ISE (normal mode), it fails with error Update-SPSolution : Access denied
When I let it run from Octopus, it also fails with error Update-SPSolution : Access denied
I added the following code to see whether my code runs as Administrator when ran from Octopus:
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "You do not have Administrator rights to run this script! nPlease re-run this script as an Administrator!"
Break
}
It turns out the deployment step is not ran as Administrator when ran by Octopus, although the User of the Octopus Tentacle Service has the rights to run as administrator.
How can I force Octopus to run my script as administrator?
I had come across the same issue, where the powershell script did not run as administrator and was not able to add/deploy farm solution. It was resolved for me when I changed the account which was running the OctopusDeploy Tentacle service to the farm administrator account. I performed the following steps:
Open services.msc
Find OctopusDeploy Tentacle, and change the log on account to a farm administrator account. Restart the service.
Have you tried using the SharePoint step template available in the library?
https://library.octopusdeploy.com/step-templates/7ac03a43-cb18-4e83-a114-b158a2bb2a52/actiontemplate-sharepoint-solution-deployment
PS: I'm unable to add comment, hence using this box to respond to your question.
Hope this help.
Jasmin

Task Scheduler Launching openwith.exe program instead of PowerShell script

I've have created a Powershell script that automatically connects to office 365 and sets all users default calendar permissions to reviewer. this script runs perfectly when executed manually.
but
I am trying to launch the powershell script via task scheduler on WS-2012-R2.
i run the task but when i check a test users calendar permissions its still the same "contributor".
When task scheduler starts the task, it creates a process, that process is given a process ID.
i went to check the ID in task manager it showed as "Pick an App" under the processes tab.
i right clicked and clicked details and it shows as OpenWith.exe
i checked file association and (.PS1) is associated to WindowsPowershell
i went to the scripts file location in explorer, Rclicked and changed the OPenWith from POwershell to Windows Powershell ISE and i still get the same thing when i run through task sheduler. ("pick and app & OPenWith.exe")
i have tried editing the "actions" in Task Manager to a combination of things such as.
In task shceduler properties
Program/script: was set to: C:\Powershell script\default reviewer permissions
this doesnt work
then i changed that to C:\Windows\System32\WindowsPowerShell\v1.0\POwershell and also PowerShell_ise
with C:\Powershell script\default reviewer permissions in the "add arguments (optional) section.
and visa versa
Can anyone please tell me what i can do to make this script run.
Many thanks
What happens when you launch PowerShell from a command-line (CMD and not a PowerShell Session) like:
powershell -?
as this should show the syntax needed?
For example, mine shows (Removing the extra help information):
PowerShell
[-File ]
Specifically:
-File
Execute a script file.
You should be using something like in your Scheduled Task (note: the use of quotes as well):
PowerShell -File "D:\WORK\ps\webtest.ps1"
Hope this helps!