Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:59:01+00:00 2026-06-17T18:59:01+00:00

I am trying to run this from my local machine (Win7 & PS v2.0)

  • 0

I am trying to run this from my local machine (Win7 & PS v2.0)

cls
$sess = Enter-PSSession -ComputerName blmcrmpoc
Invoke-Command -Session $sess -Scriptblock
{
$path = "C:\inetpub\logs\LogFiles"
$lastWrite = (Get-Date).AddDays(-90)
$oldLogs = Get-ChildItem -path $path -Recurse -Filter *.log | Where {$_.LastWriteTime -le $lastWrite}
if ($oldlogs.count -gt 0)
{foreach ($log in $oldLogs)
{$log.Delete()}}}

But I get this error.

***Invoke-Command : Cannot validate argument on parameter ‘Session’. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:59:02+00:00Added an answer on June 17, 2026 at 6:59 pm

    Try:

    cls
    $sess = New-PSSession -ComputerName blmcrmpoc
    Invoke-Command -Session $sess -Scriptblock
    {
        $path = "C:\inetpub\logs\LogFiles"
        $lastWrite = (Get-Date).AddDays(-90)
        $oldLogs = Get-ChildItem -path $path -Recurse -Filter *.log | Where {$_.LastWriteTime -le $lastWrite}
        if ($oldlogs.count -gt 0)
        {
            foreach ($log in $oldLogs)
            {
                $log.Delete()
            }
        }
    }
    

    With Enter-PSSession you ENTER a pssession(you start remoting it so you could write the commands directly as if it were the local machine). If you want to use Invoke-Command on a specific session, you create the session using New-Session because this creates a session without entering it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run this SQL from ASP.NET 2005 but am getting an
I am trying to run this code: ItemTaxonomy iTaxonomy = from itemTaxonomy in connection.ItemTaxonomy
I'm trying to run this script that basically reads/interprets text in from a textfile
I am trying to run a sample project from This site . Jboss starts
I'm trying to run my php App from Ubuntu Server 11.10. This App works
I'm trying to run a Lucene Java application on my local machine. I get
I'm trying to deploy a Rails application from my local machine to the VPS
I'm trying to load data from a csv file on my local machine to
I'm trying to upload a folder from my local machine to a remote server
I am trying to clone a repo and run it on my local machine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.