Deleting Shares

To delete a share using a Windows PowerShell script, you once again use the Win32_Share WMI class. As you may already suspect, the method you use is named delete.

The DeleteShare.ps1 script begins by using the param keyword to provide command-line input. One parameter is required—the name of the share to delete. The computername parameter will use localhost if a value is not specified, and will allow you to delete a local share. This line of code is shown here:

Param($shareName, $computerName="localhost")

When the script is run, it first evaluates the command-line parameters; the next line of code that is processed checks for the existence of the shareName parameter. If the shareName parameter is not supplied to the script, a message ...

Get Windows PowerShell™ Scripting Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.