samedi 24 janvier 2015

Invoke-Command Resolving Problem


I have written the following script using a post on this forum. The script deletes the files which are older than 15 days:



cls
$servers = Get-Content servers.txt
$limit = (Get-Date).AddDays(-15)
$path = "D:\Users\abhinasi\Documents\70-461sg"

ForEach ($line in $servers)
{
Invoke-Command -cn $line
{
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
}
}


After executing the script, I'm getting the following error:



Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
At D:\Users\abhinasi\Documents\abhi.ps1:8 char:1
+ Invoke-Command -cn $line
+ ~~~~~~~~~~~~~~~~~~~~~~~~


Kindly tell me what modification should I do for making this script to execute on remote server as well. Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire