Powershell invoking DTUTIL error - powershell

I'm currently in the process of building a deployment process in octopus deploy and as part of that I want to use DTUTIL to create folders and load SSIS packages to our server.
This text "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /SourceServer [servername] /FC SQL;\;[foldername], with appropriate server and folder names, which works in DOS.
Here is the rub, if I use the same code in Powershell I get an error:
$Command ="`"C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe`" /SourceServer MYSERVER /FC SQL;\;Folder1";
invoke-Expression $Command;
invoke-expression : At line:1 char:73
+ ... Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /SourceSe ...
+ ~
You must provide a value expression following the '/' operator.
At line:1 char:73
+ ... \Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /SourceServer MYSERVER ...
+ ~~~~~~~~~~~~
Unexpected token 'SourceServer' in expression or statement.
At line:1 char:1
+ invoke-expression $Command
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Has anyone got any idea how to remedy this?
Anthony

You can execute the EXE using the & operator:
& "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /SourceServer MYSERVER /FC SQL;\;Folder1
Also, the above Invoke-Expression command failed in the same way when I ran it in PowerShell directly, this doesn't appear to be an issue with running the PowerShell within Octopus.

Related

Uninstall VSTO plugin using batch file

I've to uninstall a vsto plugin. I'm using this command in powershell :
"C:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe" \Uninstall file:///C:/Users/username/source/repos/OutlookAddIn3/OutlookAddIn3/publish/OutlookAddIn3.vsto
This statement I copied from UninstallString in registry of this Add-in. But this gives following error in powershell :
At line:1 char:78
+ ... iles\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe" \Uninstall "file:/ ...
+ ~~~~~~~~~~
Unexpected token '\Uninstall' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Can someone tell the correct way of using this command?
Edit 1:
The cause of error was using \uninstall instead of /uninstall and as per the suggestion given by #Abraham Zinala, I added & before the command to make it run in PowerShell.
& "C:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe" /uninstall file:///C:/Users/username/source/repos/OutlookAddIn3/OutlookAddIn3/publish/OutlookAddIn3.vsto /silent
To make it work in using Batch file, just have to remove & previous command. The working command in batch file is :
"C:\Program Files\Common Files\Microsoft Shared\VSTO\10.0\VSTOInstaller.exe" /uninstall file:///C:/Users/username/source/repos/OutlookAddIn3/OutlookAddIn3/publish/OutlookAddIn3.vsto /silent

NuGet add within Powershell

I'm trying to execute the following NuGet add command via a PowerShell script:
Invoke-Expression "'C:\Program Files\NuGet\nuget.exe' add '\packageName.1.1.0.nupkg' -Source '\\file-server\My Nuget Packages'"
However, I keep running into the following errors:
Invoke-Expression : At line:1 char:36
+ 'C:\Program Files\NuGet\nuget.exe' add '\packageName.1.1.0.nupkg' -Source '\\fil ...
+ ~~~
Unexpected token 'add' in expression or statement.
At line:3 char:1
+ Invoke-Expression "'C:\Program Files\NuGet\nuget.exe' add '\packageName.1.1.0.nu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Is there a way to call the Nuget add script from within Powershell? If so, how would I do so?
Replace Invoke-Expression with & and remove the double quotes surrounding command line, and change single quotes to double quotes:
& "C:\Program Files\NuGet\nuget.exe" add "\packageName.1.1.0.nupkg" -Source "\\file-server\My Nuget Packages"
Although I suspect that \packageName.1.1.0.nupkg should really be .\packageName.1.1.0.nupkg

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!

"Could not find a part of the path" creating a service

I tried to create Azure cloud service using:
Create the Cloud Service
New-AzureServiceProject -ServiceName 'service-lift-and-shift' -Verbose
I am using Azure SDK 2.9 and it is giving the following error:
ServiceName: service-lift-and-shift
New-AzureServiceProject : Could not find a part of the path 'C:\Program Files (x86)\Microsoft
SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Profile\Resources\Scaffolding\General\scaffold.xml'.
At line:1 char:1
+ New-AzureServiceProject
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureServiceProject], DirectoryNotFoundException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.CloudService.Development.Scaffolding.NewAzureServiceProjectCommand
I solved this problem by copying folder
C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Resources
to
C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Profile
Since you want create a Could Service which only exists in ASM mode, you should logged in with command: Add-AzureAccount.
I logged in with Add-AzureRmAccount in the first time and I got the same error as you. But when I logged in with Add-AzureAccount in ASM mode, it works.
So make sure you were logged in ASM mode.

Windows Azure PowerShell cmdlet Error - File skipped because it was already present

Running the following Windows Azure PowerShell cmdlet for Windows Azure: Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1' generates the error below. I ran PowerShell with elevated priveleges and Get-ExecutionPolicy returns RemoteSigned.
Here is the error:
Import-Module : The following error occurred while loading the extended type data file:
Microsoft.PowerShell, C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Microsoft.WindowsAzure.Manag
ement.Websites.Types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".
Microsoft.PowerShell, C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Microsoft.WindowsAzure.Manag
ement.SqlDatabase.Types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".
At line:1 char:14
+ Import-Module <<<< 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1'
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Commands.ImportModuleCommand
The script does not complete after this error.
After half a day of being stuck on this, I just decided to continue with the steps, and it worked flawlessly. So I guess it was simply a warning, but did not effect the rest of the process. I have not had any issues as a result.