I would like delete a folder named pdf3.wgt after that .zip content of a folder (where was this pdf3.wgt) and finaly rename it in pdf3.wgt, (with windows PowerShell ISE).
prerequisite: C:\wamp64\www\pdf3\pdf3.wgt file exist
When i run (f5) this scripts created by the PowerShell ISE with module Compress-Archive and Rename-Item:
Remove-Item -Path C:\wamp64\www\pdf3\pdf3.wgt
PS C:\Users\tonys> Compress-Archive -DestinationPath C:\wamp64\www\pdf3\pdf3.zip -Path C:\wamp64\www\pdf3
PS C:\Users\tonys> Rename-Item -NewName pdf3.wgt -Path C:\wamp64\www\pdf3\pdf3.zip
in PowerShell ISE on windows 10 i got this error:
`PS C:\Users\tonys> rmdir C:\wamp64\www\pdf3\pdf3.wgt
PS C:\Users\tonys> Compress-Archive -DestinationPath C:\wamp64\www\pdf3\pdf3.zip -Path C:\wamp64\www\pdf3
PS C:\Users\tonys> Rename-Item -NewName pdf3.wgt -Path C:\wamp64\www\pdf3\pdf3.zip
Get-Process : A positional parameter cannot be found that accepts argument 'Compress-Archive'.
At line:2 char:1
+ PS C:\Users\tonys> Compress-Archive -DestinationPath C:\wamp64\www\pd ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand
Get-Process : A positional parameter cannot be found that accepts argument 'Rename-Item'.
At line:3 char:1
+ PS C:\Users\tonys> Rename-Item -NewName pdf3.wgt -Path C:\wamp64\www\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand`
Could someone tell me why use module proposed by powershell d'ont work ?
adn why he said to me '
A positional parameter cannot be found that accepts argument ?
'
++
When creating a script by copying from an interactive session do not include the command prompt.
PS C:\Users\tonys> Compress-Archive -DestinationPath C:\wamp64\www\pdf3\pdf3.zip -Path C:\wamp64\www\pdf3
PS is an alias for Get-Process and its arguments bare no resemblance to the rest of the line.
Related
Its and windows machine and trying to install Sql Server(unattended) using powershell
Write-Host "`nStarting the install of SQL Server" -ForegroundColor Green
[string]$userName = 'domain\username'
[string]$userPassword = 'xyz'
[securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force
[pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)
Start-Process -Filepath "$driveLetter\setup.exe" -ArgumentList "/ConfigurationFile=`"$temp_file_location`"" -Credential $credObject -NoNewWindow -Wait -RedirectStandardOutput $standardOutputFile -RedirectStandardError $errorOutputFile
ERROR:
PS C:\Windows\system32> C:\Users\manish\Desktop\custommain.ps1
domain
eu-west-1
fetching the password from parameter stores
Cleaning the outputfile error
finding and replacing the domains and secrets
writting the content of ini into temp file C:\xyz-softwares\ms-sql-server\scripts\batch-files\temp_ConfigurationFile.ini
Mounting SQL Server Image
Getting Disk drive of the mounted image
Starting the install of SQL Server
Start-Process : This command cannot be run due to the error: The user name or password is incorrect.
At C:\xyz-softwares\ms-sql-server\scripts\powershell\ms-sqlserver-installation.ps1:65 char:2
+ Start-Process -Filepath "$driveLetter\setup.exe" -ArgumentList "/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
SQL Installation Failed Installation with exit code
SQL Installation Failed Installation with exit code
At C:\xyz-softwares\ms-sql-server\scripts\powershell\ms-sqlserver-installation.ps1:72 char:9
+ throw $error_message
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (SQL Installatio... with exit code:String) [], RuntimeException
+ FullyQualifiedErrorId : SQL Installation Failed Installation with exit code
PS C:\Windows\system32>
I have tried with powershell with domain credentials.
Although i have exe file and windows machine is connected with domain
Tried to start process command with domain credetials.
I am having some problems running a powershell script in a targets file that is being included into some projects.
The MSBuild version is
16.11.0.36601
The following is the relevant stuff from the target file:
<PropertyGroup>
<ScriptLocation>
'$(SolutionDir)subdir\script.ps1'
</ScriptLocation>
...
</PropertyGroup>
<Exec Command="powershell -noprofile -NonInteractive -executionpolicy Unrestricted -File $(ScriptLocation)" />
My problem occurs when the property is expanded. For some reason it appears on a new line, this makes the command fail.
This is the Output:
0>powershell -noprofile -NonInteractive -executionpolicy Unrestricted -File
'C:\code\app\subdir\script.ps1'
0>The command cannot be run because the File parameter requires a file path. Supply a path for the File parameter and then try the command again.
and then script.ps1 is opened in my default editor.
So essentially it's running powershell -noprofile -NonInteractive -executionpolicy Unrestricted -File and then continuing and trying to run the next line, i.e. 'C:\code\app\subdir\script.ps1'
I can't make this work at all - even when I replace it with the documented method here: https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/advanced-enterprise-web-deployment/running-windows-powershell-scripts-from-msbuild-project-files#executing-a-windows-powershell-script-on-the-build-server
When I do that - the following happens:
0>powershell -noprofile -NonInteractive -executionpolicy Unrestricted -Command "&{ &'
C:\code\app\subdir\script.ps1
' } "
0>The string is missing the terminator: '.
0> + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
0> + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
0>
0>''' is not recognized as an internal or external command
...
Is there a way to tell MSBuild NOT to expand the property on a new line? If not, Is there a way I can wrap things so this doesn't happen?
Rewriting the script in batch or equivalent is not really an option.
When defining a property, it includes any line breaks into that property.
This:
<ScriptLocation>
'$(SolutionDir)subdir\script.ps1'
</ScriptLocation>
is not the same as this:
<ScriptLocation>'$(SolutionDir)subdir\script.ps1'</ScriptLocation>
I am writing a Powershell script to upload multiple folders and sub folders to the AWS S3 bucket, it is giving the below error. I recreated the same for uploading a single folder and the error remains the same. But when i try to upload files using the -File parameter it is working fine. Could someone help me out here.
Write-S3Object -BucketName my-bucket -Folder "D:\Testfolder" -Key "****/****" -Recurse
-Credential $AWSCreds -Region us-east-1.
Write-S3Object : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Write-S3Object -BucketName teamsite-s3 -Folder "D:\Testfolder\" -Key ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Write-S3Object], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet
This has been fixed by using the parameter -Keyprefix instead of -Key
This Did not work
Write-S3Object -BucketName my-bucket -Folder "D:\Testfolder" -Key "****/****" -Recurse -Credential $AWSCreds -Region us-east-1.
This Works
Write-S3Object -BucketName my-bucket -Folder "D:\Testfolder" -Keyprefix "****/****" -Recurse -Credential $AWSCreds -Region us-east-1.
I have been trying to run a flume agent on my windows system to get twitter data. I am following this blog
https://acadgild.com/blog/streaming-twitter-data-using-flume
But, whenever i try to run the flume agent I get the follwing error -
flume-ng agent -n TwitterAgent -f ./conf/flume.conf
E:\apache-flume-1.7.0-bin\apache-flume-1.7.0-bin\bin>powershell.exe -NoProfile -InputFormat none -ExecutionPolicy unrestricted -File E:\apache-flume-1.7.0-bin\apache-flume-1.7.0-bin\bin\flume-ng.ps1 agent -n TwitterAgent -f ./conf/flume.conf
Resolve-Path : Cannot find path 'E:\apache-flume-1.7.0-bin\apache-flume-1.7.0-bin\bin\conf\flume.conf' because it does not exist.
At E:\apache-flume-1.7.0-bin\apache-flume-1.7.0-bin\bin\flume-ng.ps1:217 char:24 + $confFile = '"' + (Resolve-Path $confFile).Path + '"' + ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (E:\apache-flume...conf\flume.conf:String) [Resolve-Path], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand
I have tried debugging it on my own, but have failed to do so. I tried to look for this particular error but could not find it anywhere.
Does E:\apache-flume-1.7.0-bin\apache-flume-1.7.0-bin\bin\conf\flume.conf exist at that location? Are you sure it's in \bin\conf\flume.conf and not \conf\flume.conf? In which case use:
flume-ng agent -n TwitterAgent -f ./../conf/flume.conf
Or (as is more common), run from the E:\apache-flume-1.7.0-bin\apache-flume-1.7.0-bin folder with the command:
bin/flume-ng agent -n TwitterAgent -f ./conf/flume.conf
I'm very new to PowerShell. While looking up information about error handling I've found a lot of references to using "$?"
I know that it has something to do with errors but what exactly is it? And where can I read more about it?
All of my Google searches have found nothing.
From the The Essential Windows PowerShell Cheat Sheet:
Errors and Debugging: The success or failure status of the last command can be determined by checking $?
Example:
> Get-Content file-that-exists.txt
Hello world
> Write-Host $?
True
> Get-Content file-that-does-not-exist.txt
Get-Content : Cannot find path 'C:\file-that-does-not-exist.txt' because it does not exist.
At line:1 char:1
+ Get-Content file-that-does-not-exist.txt
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\file-that-does-not-exist.txt:String) [Get-Content], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
> Write-Host $?
False
Just after asking this I discovered the command
"Get-Help -name about_automatic_variables"
This gives information about every automatic variable in powershell, it's very helpful