This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.
We actually expect you to make an own attempt to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.
Regardless of that - it is beyond the scope of this (or any) forum to teach you how to use a complex technology like a scripting language. You will have to learn the very fundamentals of PowerShell first.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
I’m not completely sure if I got what you mean. If all single steps working by themselfs you simply save them in text file with the extrension .ps1 and you have a PowerShell script.
well i want them to be as a single script if i do as you mentioned save as ps1, and set it in task schedule would it know to execute it one after the other?.
anyway my step2 code is throwing errors…so im stuck
Sorry if that sounds rude but how should we know that when you don’t tell us? Please keep in mind we cannot see your screen and we cannot read you mind.
So please post your code formatted as code along with the COMPLETE error messages you get (formatted as code as well !! ).
PS C:\Windows\system32> Expand-Archive -Path \\xx.xx.xx.xx\SanctionList\JAG01TD_WorldCompliancePlus*.Zip | Where-Objec
t { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } | -DestinationPath D:\Omni_DataMart_Lexisnexis\DataSource -Force
-DestinationPath : The term '-DestinationPath' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:149
+ ... LastWriteTime -gt (Get-Date).AddDays(-1) } | -DestinationPath D:\Omni ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (-DestinationPath:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
this is what I get, should I save it as a ps1 file and run it as I just executed it in powershell ise
PS C:\Windows\system32> $Path = '\\x.x.x.x\SanctionList\JAG01TD_WorldCompliancePlus*.Zip'
$DestinationPath = 'D:\Omni_DataMart_Lexisnexis\DataSource'
Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-1) }
Expand-Archive : The archive file path
'\\x.x.x.x\SanctionList\JAG01TD_WorldCompliancePlus*.Zip' specified as
input to the Path parameter is resolving to multiple file system paths.
Provide a unique path to the Path parameter where the archive file has to be
created.
At line:3 char:1
+ Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (\\192.168.21.2\...liancePlus*.
Zip:String) [Expand-Archive], IOException
+ FullyQualifiedErrorId : InvalidArchiveFilePath,Expand-Archive
the zip file is also password protected where do I insert the password during unzip?
PS C:\Windows\system32> $Path = '\\x.x.x.x\SanctionList\JAG01TD_WorldCompliancePlus_"*".Zip'
$DestinationPath = 'D:\Omni_DataMart_Lexisnexis\DataSource'
Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
Get-ChildItem -Path $DestinationPath -Filter * -File |
Where-Object { $_.LastWriteTime -le (Get-Date).AddDays(-1) } |
Remove-Item -Force
Expand-Archive : The path '\\x.x.x.x\SanctionList\JAG01TD_WorldCompliancePlus_"*".Zip' either does not exist or is not a valid file system path.
At line:3 char:1
+ Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (\\192.168.21.2\...ncePlus_"*".Zip:String) [Expand-Archive], InvalidOperationException
+ FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Expand-Archive
‘\x.x.x.x\SanctionList*JAG01TD_WorldCompliancePlus_"".Zip’**
If i have multiple files ending by date in folder name how do I specify it? I used the linux * which works fine there but in powershell and its password protected zip file pls advise where to insert password?
i tried this now @Olaf it does extract the folder but it also takes each and every folder and tries to unzip into destination path with error below, im not even sure how it did unzip when I didnt specify password
PS C:\Windows\system32> $SourceDir = '\\x.x.x.x\SanctionList\'
$DestinationDir = 'D:\Omni_DataMart_Lexisnexis\DataSource'
$FileNameAndExtensio = "places.sqlite"
Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
Get-Childitem –Path "$SourceDir" -Include "$FileNameAndExtension" -File -Recurse | Copy-Item -Destination "$DestinationDir" | Where-Object { $_.LastWriteTime -le (Get-Date).AddDays(-1) } | Remove-Item -Force
Expand-Archive : The path '\\x.x.x.x\SanctionList\JAG01TD_WorldCompliancePlus_"*".Zip' either does not exist or is not a valid file system path.
At line:4 char:1
+ Expand-Archive -Path $Path -DestinationPath $DestinationPath -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (\\x.x.x.x\...ncePlus_"*".Zip:String) [Expand-Archive], InvalidOperationException