วันอาทิตย์ที่ 12 กุมภาพันธ์ พ.ศ. 2566

PowerShell สคริปลบ Folder และ Files

------ Start Script --------------------------------------------------------

#Folder Path

$FolderPath = "D:Test1"

 

#Check if folder exists

If (Test-Path $FolderPath) {

    # Folder not exist, delete it!

    Remove-Item -Path $FolderPath -Recurse

    Write-host "Folder Deleted at '$FolderPath'!" -f Green

}

Else {

    Write-host "Folder '$FolderPath' does not exists!" -f Red

}

------ End Script --------------------------------------------------------

PowerShell การเปิดสิทธิ์ให้ run ไฟล์สคริป เช่น delfile.ps1 ได้

PowerShell การเปิดสิทธิ์ให้ run ไฟล์สคริป เช่น delfile.ps1 ได้

- ให้เรียกใช้ powershell 

- ให้พิมพ์คำสั่ง

วิธีการเปิดสิทธิ์ให้เรียกใช้ PowerShell ได้

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser


วิธีการปิดสิทธิ์ไม่ให้เรียกใช้ PowerShell ได้

Set-ExecutionPolicy Restricted -Scope CurrentUser


- เรียกใช้ไฟล์สคริป เ่ช่น .\delfile.ps1