8 COMMENTS

  1. Can I use this script with this:
    $computers = Get-Content .\comps.txt | Get-ADComputer -ErrorAction Continue
    So can deleta all users on multipla computers at once?

  2. When I run the above command I am getting error

    Invoke-Command : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
    At line:1 char:1
    + Invoke-Command -ComputerName $ “Compuer-name” -ScriptBlock {
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (System.String[]:String[]) [Invoke-Command], ArgumentException
    + FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.InvokeCommandCommand

  3. $user = Read-Host “Enter User Name”
    $computers = Get-Content “D:\Temp\computers.txt”
    Write-Host(“”)

    ForEach ($Computer in $Computers)
    {
    Write-Host “Processing $Computer” -NoNewLine
    Try {
    Invoke-Command -ComputerName $computer -ScriptBlock {
    param($user)
    $localpath = ‘c:\users\’ + $user
    Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -eq $localpath} |
    Remove-WmiObject
    } -ArgumentList $user -ErrorAction Stop
    Write-Host “`t…Completed”
    }
    Catch
    {
    Write-Host “`t…Connection timed out”
    }

    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here