Install .cer certificate in "Trusted Devices" folder via PowerShell - powershell

I need to install .cer certificate into "Trusted Devices" folder because I have PowerShell script which automatically installs software and only thing that is blocks the hole script is windows which asks about trustworthy of the dongle driver.
I use this cmdlet inside Vagrant
vagrant.exe powershell -c "Import-Certificate -Filepath C:\vagrant\Microcosm.cer -CertStoreLocation Cert:\Local Computer\TrustedDevices"
Here is error message output
vagrant.exe : The following WinRM command responded with a non-zero exit status.
At line:1 char:2
+ vagrant.exe powershell -c "Import-Certificate -Filepath C:\vagrant\Microcosm.ce ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (The following W...ro exit status.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Vagrant assumes that this means the command failed!
Import-Certificate -Filepath C:\vagrant\Microcosm.cer -CertStoreLocation Cert:\Local Computer\TrustedDevices
Stdout from the command:
Stderr from the command:
#< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">Import-Certificate : A positional parameter cannot be found that accepts argument 'Computer\Trust
edDevices'._x000D__x000A_</S><S S="Error">At line:1 char:40_x000D__x000A_</S><S S="Error">+ ... lyContinue';Import-Certificate -Filepath C:\vagrant\Microcosm.cer -Ce ..._x000D__x000A_</S><S
S="Error">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S="Error"> + CategoryInfo : InvalidArgument: (:) [Import-Certificate], P
arameterBindingException_x000D__x000A_</S><S S="Error"> + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.CertificateServices.Commands.ImportCertificateComm _x000D__x000A_</
S><S S="Error"> and_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>

Cert:\Local Computer\TrustedDevices has a space in it. Try this with escaped quotes around your path:
vagrant.exe powershell -c "Import-Certificate -Filepath C:\vagrant\Microcosm.cer -CertStoreLocation `"Cert:\Local Computer\TrustedDevices`""

Related

Powershell Certificate Import From RootCA

With the GUI I just use MMC \ Certificates and do an import and point to my AD integrated certificate for ldaps, how can i accomplish this with powershell
I am trying this to no avail
Get-Certificate -Template ldaps -CertStoreLocation cert:\localmachine\MY -Credential $cred -Url http://rootca/certsrv
Error:
Get-Certificate : CX509EnrollmentPolicyWebService::Initialize: The parameter is incorrect. 0x80070057 (WIN32: 87 ERROR_INVALID_PARAMETER). This may be the result of user credentials being required on the remote machine. See Enable-WSManCredSSP Cmdlet help on
how to enable and use CredSSP for delegation with PowerShell remoting.
At line:1 char:1
+ Get-Certificate -Template Computerv2 -CertStoreLocation cert:\localma ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Certificate], Exception
+ FullyQualifiedErrorId : RemotingFailure,Microsoft.CertificateServices.Commands.GetCertificateCommand
certreq -enroll -machine -q "LDAPS_CERTIFICATE"

Installing CCM client on PC via powershell

I'm trying to speed up how soon SCCM recognises a device on the domain and starts the process of installing applications.
I have the below in powershell
$CCMInstallerPath = "\\ServerFQDN\SMS_MAN\Client\ccmsetup.exe"
$args = "/mp:MPServer", "/LOGON", "/UsePKICert", "SMSSLP=SMSSLPServer", "SMSSITECODE=MAN"
& $CCMInstallerPath $args
I get the below error:
Program 'ccmsetup.exe' failed to run: Access is deniedAt line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
I have read and execute access to this file, both by group and directly by name
I have also tried:
Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\ccmsetup.exe -ArgumentList "/mp:MPServer", "/logon SMSSITECODE-MAN", "/UsePKICert"
and get the error
Start-Process : This command cannot be run due to the error: Access is denied.
At line:1 char:5
+ Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
ServerFQDN is a replacement for one of our NM servers
I can fully connect to the folder and run the exe manually
I am running elevated powershell
Issue was caused by incorrect share permissions found in effective access.
Permission was granted to run the file but effective access was showing differences

why am I getting this error in windows powershell?

I was trying these power forensics command from this website the 1st two commands worked perfectly while the next 3 commands gave errors, I am sharing one of the error below. Please tell me the solution to get rid of this error.
Command - PS C:> Get-ForensicFileRecord -Path C:\Windows\system32\cmd.exe
Error:
Get-ForensicFileRecord : Path C:\Windows\system32\cmd.exe not found.
At line:1 char:1
Get-ForensicFileRecord -Path C:\Windows\system32\cmd.exe
+ CategoryInfo : NotSpecified: (:) [Get-ForensicFileRecord], Exception
+ FullyQualifiedErrorId : System.Exception,PowerForensics.Cmdlets.GetFileRecordCommand
The link which I followed for this tutorial:
PowerForensics - PowerShell Digital Forensics | Get-ForensicFileRecord

Import pfx file with sn.exe using powershell

I am trying to install pfx file automatically every time the Azure Pipeline runs. Below is the powershell script i am trying to implement. I need it to provide the password automatically:
Set-Location "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools"
Start-Process -FilePath "sn.exe" -ArgumentList "-d",$container
Start-Sleep 2
Start-Process -FilePath ".\sn.exe" -ArgumentList "-i","c:\cert_2013.pfx",$container -NoNewWindow
Start-Sleep 2
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("$($CerPass){ENTER}")
Start-Sleep 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
When the pipeline runs the ps1 file it is erroring out at SendWait("$($CerPass){ENTER}") Step. Below is the exact error message:
Enter the password for the PKCS#12 key file:
Could not read password for PKCS#12 blob in c:\cert_2013.pfx --
Console input may not be redirected for password entry.
Exception calling "SendWait" with "1" argument(s): "Access is denied"
At line:1 char:1
+ & 'C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Exception calli...cess is denied":String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
At C:\PowerShellScript\CertReInstall.ps1:18 char:46
+ [System.Windows.Forms.SendKeys]::SendWait("$($CerPass){ENTER}")
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : Win32Exception
[error]Non-Zero exit code: '1' for ComputerName: 'PQAFCTC1'
[error]Atleast one remote job failed. Consult logs for more details. ErrorCodes(s): 'RemoteDeployer_NonZeroExitCode'
[section]Finishing: Run PowerShell on Target Machines
I need it to be automatically send the password to the file when installing. When i run the ps1 file directly on the server it works fine, but I need this script to be part of pipeline task (azure devops pipeline).
Any help would be greatly appreciated.
Thank you!

Powershell: Running a .msc applet as another user

I'm currently writing a powershell script that asks for a single set of admin credentials, and uses those to run relevant applications, pulled from a network-hosted CSV. When I try to run
Start-Process $tools[$userInput-1].path.toString() -credential $credential
(where $tools is returning "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange Management Console.msc") I get the error below
Start-Process : This command cannot be executed because the input "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange Management Console.msc" is an Invalid Application. Give a valid application and Run your command again.
At line:1 char:14
+ Start-Process <<<< "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange Management Console.msc" -credential
Get-Credential
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
If I need to, I'll just write a .bat file and run that, but I'd rather avoid that whenever possible.
And the reason I'm not using Invoke-Item is because it can't take -Credential, even if the man file says otherwise.
.msc is a saved console file, the host of which is mmc, so to start this from powershell you could use syntax similar to the following:
$mmcPath = "C:\Windows\System32\mmc.exe"
$mscPath = "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange Management Console.msc"
Start-Process -FilePath $mmcPath -ArgumentList $mscPath