Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, January 24, 2015 11:22 AM
Hi,
Is there any example to delete files which starting with DA*, and file extension are DLL and DLA?
Thanks,
All replies (8)
Wednesday, February 4, 2015 5:47 AM ✅Answered
Hi MASTER AX,
If you can use powershell cmdlet, and want to delete all the files which starting with DA* and file extension are DLL under a shared foler (because you said "remote server" in the title), please refer to this script, if you want to execute the delete operation, please remove the parameter -whatif:
Get-ChildItem \\remotepc\folder\da*.dll -Recurse|Remove-Item -Recurse -WhatIf
If there is anything else regarding this issue, please feel free to post back.
If you have any feedback on our support, please click here.
Best Regards,
Anna Wang
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]
Wednesday, February 4, 2015 10:32 PM ✅Answered | 1 vote
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/del.mspx?mfr=true
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
$session = New-PSSession -ComputerName MyRemoteServer1, MyRemoteServer2
Invoke-Command -Session $session {del da*.dll}
Invoke-Command -Session $session {del da*.dla}
These commands will run the del command on the two remote servers that are named MyRemoteServer1 and MyRemoteServer2, sub your server names
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
Actually the documentation link is incorrect. It is the doc for the old DOS/CMD del command whioch si built into CMD.EXE and cannot be run from PowerShell without CMD.EXE
Try these to see what I mean.
cmd /c del /?
del /?
del -?
DEL in PowerShell runs Remove-Item.
The is also no need to create a whole buch of connectiosn when we can do it all at once.
Invoke-Command -script { remove-item -path c:\test\ -Include *.dll,*.dla -WhatIf } -computers comp1,comp2,comp3
Sessions are useful when we need to maintain long term connections. Sessions are expensive.
¯\(ツ)_/¯
Saturday, January 24, 2015 11:44 AM
del da*.dll
del da*.dla
¯\(ツ)_/¯
Saturday, January 24, 2015 11:54 AM
Thanks,
How about if I would like to delete the files under folder "c:\temp"?
Saturday, January 24, 2015 11:57 AM
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/del.mspx?mfr=true
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
Wednesday, February 4, 2015 10:06 PM
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/del.mspx?mfr=true
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
$session = New-PSSession -ComputerName MyRemoteServer1, MyRemoteServer2
Invoke-Command -Session $session {del da*.dll}
Invoke-Command -Session $session {del da*.dla}
These commands will run the del command on the two remote servers that are named MyRemoteServer1 and MyRemoteServer2, sub your server names
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
Wednesday, February 4, 2015 10:58 PM
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/del.mspx?mfr=true
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
$session = New-PSSession -ComputerName MyRemoteServer1, MyRemoteServer2
Invoke-Command -Session $session {del da*.dll}
Invoke-Command -Session $session {del da*.dla}
These commands will run the del command on the two remote servers that are named MyRemoteServer1 and MyRemoteServer2, sub your server names
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
Actually the documentation link is incorrect. It is the doc for the old DOS/CMD del command whioch si built into CMD.EXE and cannot be run from PowerShell without CMD.EXE
Try these to see what I mean.
cmd /c del /?
del /?
del -?
DEL in PowerShell runs Remove-Item.
The is also no need to create a whole buch of connectiosn when we can do it all at once.
Invoke-Command -script { remove-item -path c:\test\ -Include *.dll,*.dla -WhatIf } -computers comp1,comp2,comp3
Sessions are useful when we need to maintain long term connections. Sessions are expensive.
¯\(ツ)_/¯
Thanks jrv, good point, either way will get it done,
use: Invoke-Command -script { remove-item -path c:\test\ -Include *.dll,*.dla -WhatIf } **-computername comp1,comp2,comp3 ** https://technet.microsoft.com/en-us/library/hh849719.aspx no computers parameter
Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com
Wednesday, February 4, 2015 11:27 PM
Sure look like a commputername to me. It hels to actually look these things up. The eye can be fooled very easily.
Try this at any prompt:
invoke-command -script {dir} -ComputerName $env:computername
PS C:\scripts> help Invoke-Command -par computername
-ComputerName <String[]>
*** Specifies the computers on which the command runs. The default is the local computer.***
*** When you use the ComputerName parameter, Windows PowerShell creates a temporary connection that is used only to run the specified command and is then closed. If you need a***
*** persistent connection, use the Session parameter.***
*** Type the NETBIOS name, IP address, or fully-qualified domain name of one or more computers in a comma-separated list. To specify the local computer, type the computer name,***
*** "localhost", or a dot (.).***
*** To use an IP address in the value of the ComputerName parameter, the command must include the Credential parameter. Also, the computer must be configured for HTTPS***
*** transport or the IP address of the remote computer must be included in the WinRM TrustedHosts list on the local computer. For instructions for adding a computer name to the***
*** TrustedHosts list, see "How to Add a Computer to the Trusted Host List" in about_Remote_Troubleshooting.***
*** Note: On Windows Vista, and later versions of Windows, to include the local computer in the value of the ComputerName parameter, you must open Windows PowerShell with the***
*** "Run as administrator" option.***
*** Required? false***
*** Position? 1***
*** Default value Local computer***
*** Accept pipeline input? false***
*** Accept wildcard characters? false***
¯\(ツ)_/¯