Ignore popup windows when executing powershell script Request-Certificate.ps1 - powershell

In order to request a User ceritificate I'm using the script provided by the Powershell gallery https://www.powershellgallery.com/packages/Request-Certificate/1.5.0/Content/Request-Certificate.ps1
To execute this script I'm using the following command:
. "C:\Certificates\RequestCertificate.ps1" -CN "User Common Name" -TemplateName "User" -CAName "domain\CAserver" -Export
However when I run this command here is the output:
After this output I get a popup message with the following information:
Machine context template conflicts with user context.
If I click ok, the request is concludes successfully. However I'm trying to automate this process. Is there a way to ignore the popup window?
I already looked at the question How to suppress a popup window while using certreq to request a certificate from an enterprise CA? (How to suppress a popup window while using certreq to request a certificate from an enterprise CA?). However the solution for the problem described was to run the script as Admin or System because the certificate generated was for the Machine and not for the User.
Does anyone know why this is happening?
Thank you in advance

Related

How to list all Power Platform solutions using PowerShell or Microsoft Graph API?

I'm looking to for way to get an entire Power Plateform list of solutions. The aim is to export all the solutions with their properties (i.e. Name, id, date of creation, etc).
As you know, solutions can contains, Power Apps application, Power Automate flows, environment variables and so on.
I already know that Power Apps applications (canvas apps) can be retreived by using this command line:
Get-AdminPowerApp
And Flows can be retreived by using this one:
Get-AdminFlow -EnvironmentName "env"
We can found command line to get environements, connections, connectors, etc.
Is there a command line that look like the following one ?
Get-AdminPowerAppsSolution -Environment "env"
Thank you all.
To be able to get solutions with PowerShell an additional PowerShell module is required and can be install by typing the following command-line:
Install-Module Microsoft.Xrm.Data.Powershell
Once the module is installed, a connection to crm online is required :
Connect-CrmOnlineDiscovery -InteractiveMode
The InteractiveMode option prompt a modal to allow the user to enter his credentals. Connection can also be acheived by creating credental manually and then pass it as a parameter:
$creds = Get-Credential
Connect-CrmOnlineDiscovery -Credential $creds
Which prompt a login window as well, but once the credental is set, it can be reused for further calls.
And finally, a lasts commands as follow :
$records = Get-CrmRecords -EntityLogicalName solution
$records.crmRecords
The crmRecords attributes contains all the solution for the selected environment with the following properties :
ReturnProperty_EntityName
solutionid
solutionid_Property
ReturnProperty_Id
EntityReference
original
logicalname
Finding all apps across all environments to which you have admin access can be done with the following command:
Get-AdminPowerApp
More information about this command can be found on Microsoft docs here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powerapps.administration.powershell/get-adminpowerapp?view=pa-ps-latest
You can get PowerApps Solutions by installing the PowerApps CLI.
Look at the Solution export command.
Example:
pac solution export --path c:\Users\Documents\Solution.zip --name SampleComponentSolution --managed true --targetversion 10.0.03 --include general

Powershell script to show file extensions in File Explorer

I'm fairly new to the world of Powershell and currently I'm trying to push a Powershell script via Intune to the company devices (all Windows 10 21H2 machines) that will show the file extensions in File Explorer.
So far, I've found this:
Set-Itemproperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'HideFileExt' -value 0
The PS script is pushed via Intune to a test device and the monitor tells me the policy is applied successfuly but the file extensions are still not visible.
Is there something wrong with the line of code?
My original comment which helped:
The script works fine. I am positive that it is not applied successfully, despite Intune telling you it did. While it is not part of that question, I suppose you should check the user context in which the script is applied and if the eventvwr or any other possible source tells you why the script did not apply correctly. Also, after trying the script locally for myself, you need to refresh the explorer tab via f5 for the change to apply.
Solution was to set it as system/device rights, since it was indeed run as user context, hence solving the problem.
This was the solution:
"The script works fine. I am positive that it is not applied successfully, despite Intune telling you it did. While it is not part of that question, I suppose you should check the user context in which the script is applied and if the eventvwr or any other possible source tells you why the script did not apply correctly. Also, after trying the script locally for myself, you need to refresh the explorer tab via f5 for the change to apply" –
Bowshock

How to automate user input to a executable?

I have a .exe file which when called from the Windows Command prompt, first connects to a server and then requests for user input as a confirmation.
Something like below:
C:\SomePath\AnotherFolder>TheApplication.exe download
Logging in to Vault server myserver.app.cosmos...
Logged in to the Vault server
Downloading will overwrite existing files.
Download scripts for context 'COSMOS' to folder:
C:\Work\MyFolder\TEST?
(y/n): n <--- n was my input
Press any key to exit... <--- here i pressed y
I want to automate this process.
I tried the below line from the Windows command prompt:
echo n|TheApplication.exe download
I even tried :
(echo n && echo y)|TheApplication.exe download <-- the y for the last user input request to close the app.
But in both cases its throwing the below error:
Unhandled Exception: System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.
at System.Console.ReadKey(Boolean intercept)
at System.Console.ReadKey()
at TheApplication.Program.Main(String[] args)
**disclaimer: TheApplication.exe is a third party executable. I cannot change anything inside it.
PS: If needed I can run this from a powershell console if its not possible from windows command prompt or I can also include the whole thing inside a batch script.
But any how I need to automate this.
If you can use PowerShell...
autoinput.ps1
Add-Type -AssemblyName System.Windows.Forms
Start-Sleep -m 1000
[System.Windows.Forms.SendKeys]::SendWait("ny")
The command is:
powershell .\autoinput.ps1 & .\TheApplication.exe

Get-Process cannot get the latest path

considering the following scenario:
I run the executable on the server
I renamed the executable files to a different one while the process is still running.
then use get-process -ID 50620 | Select * to list detail information of this specific process
the path shows previous data, while the actual executable file name was changed already...
how can I get the latest file name from the PowerShell?
Thanks!
why i am asking this:
we are using Terminal server for PDA applications, so once we updated the executable on server, we modify the pervious executable name to different one so when RDP users login system will automatically load the new executable.
just trying to get those sessions running pervious executable(who doesn`t logout and login again since the update) to send message so they know the executable was updated and they have so logout and login soon to load the latest code.

Task scheduler "Run whether user is logged on or not" issue to startup application

I have a .bat file that starts up a powershell script.
Within this powershell script, i startup PowerBI with a given database.
The powershell script waits till powerBI has been done starting up, and will then be exporting data to some datadump files.
Doing this manually works fine, and also when its on the task scheduler to run when user is logged on.
The moment i change this to "Run whether user is logged on or not" it doesnt work anymore.
The reason behind this, is that it seems that powershell is unable to start PowerBI and therefore there is no open data to query in the rest of the script.
So the positive side is it runs the bat and powershell just fine, only the powershell itself seems incapable to start powerBI.
Are there any solutions to this? should i for example use a different method to call the appliation to start?
currently the powershell snippit to start the app looks like this:
$PBIDesktop = "C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe"
$template = "C:\LiveData\Data.pbix"
$waitoPBD = 60
$app = START-PROCESS $PBIDesktop $template -PassThru
log_message "Waiting $($waitoPBD) seconds for PBI to launch"
Start-Sleep -s $waitoPBD
I faced similar issue. So, sharing my experience..
First of all, please verify couple of things.
Specify user account which will be used to invoke the job. Also, ensure that, the account have sufficient permission.
Don't forget to un-check the checkbox (as shown in screenshot) under Conditions Tab
Just found this one - sorry it took so long :D
But, i had this totally nervwrecking issue to.
Solution for me is to realize that the task scheduler is very deep part of the OS.
Thats why i have to grant access to the file, for the computername$ (system name) on the file or folder containing the file to run.
Rightclick on the file or folder -> Security. Select edit and add [Name of your computer]$ and give the read and execute permissions.
That's the only way I can make it run.
But i hope you found the solution in the meantime :)