Could anyone please assist me on this issue? I have been trying to resolve this issue from last one week but I am not able to resolve this and need your help.
What is the goal of this script?
- Need to delete big SQL dump files remotely.
- When script is launched, we need to click on ok while parent folder is selected/highlighted.
- After then we need click on ok so that we can go to its subfolder.
- Finally we need to select the files and hit OK. It will delete the selected files.
- For this, a GUI PS script needs to be created.
- Files to be deleted are under subfolder of another subfolder.
Error while executing this script:
**`Get-ChildItem : Cannot find path ‘C:UsersUjjwal Mandal@{name=All Documents; Size=6.18 GB}’ because it does not exist.
At D:projecttest.ps1:30 char:20
- $child1= $output | Get-ChildItem | Out-GridView -Title “Select server …`
**
My PowerShell code for this
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$TempFile = [io.path]::GetTempFileName()
$form = New-Object System.Windows.Forms.Form
$form.Text = "Fix low space issue"
$form.size = New-Object System.Drawing.Size(900,400)
$remdmp = New-Object System.Windows.Forms.Button
$remdmp.Location = New-Object System.Drawing.Size(300,35)
$remdmp.Size = New-Object System.Drawing.Size(300,45)
$remdmp.Text = "Remove dump Files"
$remdmp.Font = [System.Drawing.Font]::new('Microsoft Sans Serif', 10, [System.Drawing.FontStyle]::Bold)
$remdmp.Add_Click({
Remove-Item $TempFile -ErrorAction SilentlyContinue
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$svrs ="TM-ND0276"
$path = "\TM-ND0276d$"
$size = 0
$decimalPlaces = 2
$output = @()
$data=Get-ChildItem -Directory $path | ForEach-Object {
$size += (Get-ChildItem -Recurse $_.FullName | Measure-Object -Property Length -Sum).Sum
$output += New-Object PSObject -Property @{
name = $_.Name
Size = "{0:N$decimalPlaces} GB" -f ((Get-ChildItem -Recurse $_.FullName | Measure-Object -Property Length -Sum).Sum / 1GB)
}
}
$output | Sort-Object -Descending -Property Size | Out-GridView -Title "select" -PassThru
$child1= $output | Get-ChildItem | Out-GridView -Title "Select server name folder you want to delete the dump files from" -PassThru
$child2= $child1 | Get-ChildItem | Out-GridView -Title "Select files you want to delete" -PassThru
if($child2) {
$child2 | Remove-Item -Recurse -Force
$msgbox=[System.Windows.MessageBox]::Show('Dump files have been deleted. Check notepad for available free space in D drive')
$dskspce=Invoke-Command -ComputerName $svrs -ScriptBlock {Get-WmiObject -Class win32_logicaldisk | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}} }
$dskspce | Format-Table > $TempFile | Notepad $TempFile
}
else{
$msgbox=[System.Windows.MessageBox]::Show('Action has been cancelled. Script will stop here!')
}
})
$Form.Controls.Add($remdmp)
$QUIT = New-Object 'System.Windows.Forms.Button'
$QUIT.DialogResult = 'OK'
$QUIT.Location = '300, 200'
$QUIT.Margin = '5, 5, 5, 5'
$QUIT.Name = 'buttonOK'
$QUIT.Size = '300, 50'
$QUIT.BackColor ="LightGray"
$QUIT.ForeColor ="black"
$QUIT.Text = '&CLOSE'
$QUIT.Font = [System.Drawing.Font]::new('Microsoft Sans Serif', 10, [System.Drawing.FontStyle]::Bold)
$QUIT.UseCompatibleTextRendering = $True
$QUIT.UseVisualStyleBackColor = $False
$QUIT.Add_Click({$form.Add_FormClosing({$_.Cancel=$false});$form.Close()})
$QUIT.Show()#$QUIT.Hide()
$form.Controls.Add($QUIT)
$form.showdialog()
It looks like object TypeName of output should be “System.IO.DirectoryInfo” however, it is “System.Management.Automation.PSCustomObject” that’s why I am getting this error?
Could anyone please take a look and assist me here? Kindly let me know if you any question.
I have tried all the articles I found on the internet also gone through a PowerShell book but didn’t find much information regarding this error and resolution.
When I click on OK button(after selecting any subfolder folder) it should take me to another subfolder but unfortunately it is not.
Screenshot of this gui and issue:
GUI Script view and sufolders
Error when I click on ok after select a folder
Ujjawal Mandal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.