Thanks for taking the time to read my post!
I'm new to scripting and I've got a workaround, but it's clumsy. Any tips would be appreciated.
Expand-archive -path $home\Downloads\SWANDPDM_SP5.1.zip -DestinationPath C:\temp\swpdminstaller\extracted\ -Force
Start-sleep -seconds 600
Invoke-Item C:\temp\swpdminstaller\extracted\SOLIDWORKS_AND_PDM_2021_SP5.1\startswinstall.exe
How can I tell PowerShell to wait until the decompression occurs, before running the file?
Thanks all!
Related
This is my first form I'm making to accomplish a task, but also to learn how to do it. I'm making a simple front end for exporting and then importing WSUS data from a connected server to a disconnected server. I'm working on the export part now and I need to figure out how to start the export process, then once it is done then make the iso file.
Here is the button code I have so far, but not sure how to watch the WsusUtil.exe until it's done then proceed to the next task. I thought I could watch the process and when it's over move to the next step. But have not been able to make that work. I tried a do until, but it kept running the start-process over and over. Also when it starts it make a large black box with some message on it. I tried to use the -NoNewWindow but it did launched. WsusUtil.exe running
$btnStartExport.Add_Click({
$nicedate = get-date -UFormat %m-%d-%y #put in MM-DD-YY format
#progress bar for overall progress of steps 1 and 2 and individual progress bar for each steps
$WSUSUtilPath = "c:\Program Files\Update Services\Tools\"
$WSUSMetaDataPath = "c:\tools\wsusexport\"
$isotitle = "WSUS Offline Server update $nicedate"
$ProcessName = "WsusUtil" #process to watch until it's done
$isofilename = "WSUSSvrOffline-$nicedate.iso" #creates WSUS Offline Server update-11-14-2021.iso
#Step 1 Check if directory exists
Check-Path $WSUSMetaDataPath
#Step 1 - export the WSUS Metadata
Start-process -FilePath $WSUSUtilPath\WsusUtil.exe -ArgumentList #("export","$WSUSMetaDataPath\$nicedate-export.xml.gz","$WSUSMetaDataPath\$nicedate-export.log") -NoNewWindow -Wait
$wsusProcess = get-process WsusUtil -ErrorAction SilentyContinue
# Step 2 - create ISO
get-childitem "$WSUSMetaDataPath","$txtWSUSContentPath.text" | New-IsoFile -path $txtISOLocation.text+$isofilename -Force -Title $isotitle
#clean up medatadata directory
get-childitem -path $WSUSMetaDataPath -Include *.* -File -Recurse | foreach {$_.Delete()}
})
$frmMain.controls.add($btnStartExport)
I'm trying to move the older log files (older than 7 days) from the source to the target folder using the below script:
But this code doesn't move the file. Where as when I use the below code for deleting the older files (older than 7 days) it works!
I tried saving them as .ps1 file and .bat file, but no luck in moving. Can someone please help me figure out the issue?
This will help for you..
Get-ChildItem "E:\SC\A" | where {$_.LastWriteTime -lt (Get-Date).AddDays(7)} | Move -Destination "E:\SC\B"
SharePoint does not work the same way. You need to create a PSDrive.
New-PSDrive -Name atemp -PSProvider FileSystem -Credential $cred -Root "$spdir"
Copy-Item -Path "$logfilename" -Destination "$spdir"
Remove-PSDrive atemp
When I tried mapping with the IP address it worked!
and I use -get childitem for moving.
Note: That ID address posted is just a random number I came up with. Also there was no -credential needed in my case
I have a program which generate some reports by reading .XML file and I have to generate reports for multiple files.
But the problem which I am facing is for doing this I need to run it multiple times for each files as program reads only 1 file in 1 click.
Is there any way by which I can generate reports for multiple files in one click ?
So far i have tried below codes
$a = Get-ChildItem "D:\Directory1\Files\*.xml"
foreach ($i in $a)
{
Move-Item $i "D:\Directory1\"
if ($a) {
D:\Directory1\Program1.exe /run /exit /SilentMode
}
}
As per the above code I am trying to Read files from "D:\Directory1\Files\" Then move any 1 file (Not all Files) to the directory "D:\Directory1\" and then start the Program "Program1.exe" and generate the reports and repeat it till the .xml files exist in "D:\Directory1\Files\"
Is your goal to copy all files from D:\Directory1\Files\ to D:\Directory1\ in one step and then run D:\Directory1\Program1.exe /run /exit /SilentMode?
EDIT:
This work for you?
0. Set location that your program work
1. Get all files
2. For each file
3. Move file to new location
4. Start you program
5. Remove the moved file
Set-Location -Path "D:\Directory1\"
$arrFiles = Get-ChildItem -Path "D:\Directory1\Files\*.xml"
Foreach ($objFile in $arrFiles) {
Move-Item -Path $objFile.FullName -Destination "D:\Directory1\$($objFile.Name)"
Start-Process -FilePath "D:\Directory1\Program1.exe" -ArgumentList "/run /exit /SilentMode" -Wait
Remove-Item -Path "D:\Directory1\$($objFile.Name)"
}
Your logic here was sound, however, one issue you would have is the script will continue processing even while Program1.exe is running. Thereby making it possible for it to seeminly skip files. Also your If statement is just check if $a contains data which it always will in you example. Makes the condition check mute.
What you can do is something like this.
$moveLocation = "D:\Directory1\"
Get-ChildItem "D:\Directory1\Files\*.xml" | ForEach-Object{
# Move the file to its new location
Move-Item -Path $_.FullName -Destination $moveLocation
Start-Process -FilePath "D:\Directory1\Program1.exe" -ArgumentList "/run /exit /SilentMode" -Wait
}
I would like some assistance getting a powershell script to work correctly. A piece of it is pasted below. Basically what I'm trying to do is to move all files in various subdirectories to another location. I can get the files to move and the folders to create fine, I'm just having a problem with getting the results to a text file. I've tried using out-file, but the txt file is empty. I've also tried start-transcript, but notepad doesn't seem to see line breaks and all the text bleeds together. Is there a better way to go about this? I'm using this basic command for testing.
Start-Transcript c:\log.txt
Move-Item c:\temp\*.* C:\Temp\2014 -Verbose -Force
Stop-Transcript
You may just need to collapse the output file descriptors. According to the about_Redirection page, it should work if you do the following:
Move-Item c:\temp\*.* C:\Temp\2014 -Verbose -Force *>&1 |
Out-File -FilePath $MyLogPath
Or if you want to see the output at the same time
Move-Item c:\temp\*.* C:\Temp\2014 -Verbose -Force *>&1 |
Tee-File -FilePath $MyLogPath
Here's a strange one...is there anyway of using powershell to see how long it takes to write a file?
So, if I create a file - can powershell tell me how long it took to create that file (ie 25ms or whatever the number is). Also, if I delete a file can it also tell me the time?
Thanks
Measure-Command can do this for you.
e.g.
Measure-Command { new-item -Path test.txt -ItemType File -Force }
You mean something like this?
$before = Get-Date
# do stuff
$after = Get-Date
echo ($after - $before).TotalMilliseconds