Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not connect to #38

Open
DoubleJCream opened this issue Apr 9, 2024 · 14 comments
Open

Could not connect to #38

DoubleJCream opened this issue Apr 9, 2024 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@DoubleJCream
Copy link

Hi

I just tried using your script to wipe some extra profiles off some of my users laptops and initially i had to allow the PS Man through the firewall - when i run the command
Get-RSUserProfile -ComputerName "Laptop1"
i get the listing of the profiles, however when i run the command;

Remove-RSUserProfile -ComputerName "Laptop1" -UserName "User1"
I get the error;
Could not connect to trough WinRM, please check the connection and try again

so just wondering if you know what is missing? The first indication is that it isn't displaying the computer name. I see in the code that its doing this mostly through cim session - not sure if the Get-RSUserProfile uses that as well and if so why its not working for Remove-RSUserProfile.

Let me know if you have any ideas.

PS - small typo - the spelling should be '.. through WinRM'

thanks

@rstolpe
Copy link
Owner

rstolpe commented Apr 10, 2024

You need to make sure that WinRM are activated on the computer you want to execute it against

@DoubleJCream
Copy link
Author

I checked it;

PS C:\Users\adminbe> test-wsman -ComputerName "Laptop1"
wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor : Microsoft Corporation
ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

checked on the local machine, ie Laptop1 same reply

I did a ;
enter-pssession -computername Laptop1
and it creates the PS session

also as i said it pulls the list of profiles so it is communicating with the remote machine, but obviously there is something in the code/command that it fails on.

@rstolpe
Copy link
Owner

rstolpe commented Apr 12, 2024

I checked it;

PS C:\Users\adminbe> test-wsman -ComputerName "Laptop1"

wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd

ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd

ProductVendor : Microsoft Corporation

ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

checked on the local machine, ie Laptop1 same reply

I did a ;

enter-pssession -computername Laptop1

and it creates the PS session

also as i said it pulls the list of profiles so it is communicating with the remote machine, but obviously there is something in the code/command that it fails on.

Interesting, I did try it before I did publish it.
But I'll take a look during next week and see what it can be. It might be some bad error handling or similar that breaks the script. Do you use it with PowerShell 7?

@rstolpe
Copy link
Owner

rstolpe commented Apr 12, 2024

@DoubleJCream did you try to use it with full FQDN?
Was looking in my tests and I did use laptop.Stolpe.io in them.
So try that instead of just laptop

@DoubleJCream
Copy link
Author

DoubleJCream commented Apr 16, 2024

I loaded up the script, i am certainly no powershell expert but it seems that in the first function;
Get-RSUserProfile
you have the loop ;
$JobGetProfile = foreach ($_computer in $ComputerName) {

however that loop is not defined in the function;
Remove-RSUserProfile
so when you use the $_computer I believe it is undefined, i'm not sure but even if it was defined in the previous function it wouldn't be defined in the RSUserProfile function.

I switched the variable from $_computer to $ComputerName which is defined from the command call and it seems not to report that error - i'll have to check tomorrow if its actually working but i think the issue lies that $_computer isn't defined.
Let me know

PS - i tried with fqdn (same error) and working in PS 7.3 / 7.4

@DoubleJCream
Copy link
Author

ok - i think i have it working now - it would be nice to have a bit more of an interactive menu; ie list the profiles and choose which ones to delete, but at lease the script is working i think in the way you wanted it to.

So i think in the Remove-RSUserProfile it is missing the loop for defining $_computer as mentioned above.

Also, there is an issue in the Function Confirm-RSProfile where you have the 3 parameters defined as mandatory, but in the case where you only want to delete one profile you have the call (function Remove-RSUserProfile);
$CheckProfile = Confirm-RSProfile -UserName $_profile -ProfileData $GetAllProfiles

as you see there is only 2 parameters passed, so the script waits for input of the 3rd parameter.

i hope this helps, let me know if i can be of any help

@rstolpe
Copy link
Owner

rstolpe commented Apr 19, 2024

ok - i think i have it working now - it would be nice to have a bit more of an interactive menu; ie list the profiles and choose which ones to delete, but at lease the script is working i think in the way you wanted it to.

So i think in the Remove-RSUserProfile it is missing the loop for defining $_computer as mentioned above.

Also, there is an issue in the Function Confirm-RSProfile where you have the 3 parameters defined as mandatory, but in the case where you only want to delete one profile you have the call (function Remove-RSUserProfile);

$CheckProfile = Confirm-RSProfile -UserName $_profile -ProfileData $GetAllProfiles

as you see there is only 2 parameters passed, so the script waits for input of the 3rd parameter.

i hope this helps, let me know if i can be of any help

Yeah that's a bug, was looking over the code now.
I did miss to set the exclude one to $false.

I'll update the module as soon as possible.
It was working for me as I did use the exclude.

Thanks for seeing it, have been swamped with work so I haven't had time for it.

@DoubleJCream
Copy link
Author

hey, no worries, i would need a clone or live another lifetime to get all the stuff done!
thank you for the code - it is much appreciated!

look forward to the update when you can.

@rstolpe rstolpe self-assigned this Apr 20, 2024
@rstolpe rstolpe added the bug Something isn't working label Apr 20, 2024
@molitar
Copy link

molitar commented Apr 29, 2024

OK so how do I fix this I understand nothing of what you spoke about I just know the module could not delete user with the connect error.

@DoubleJCream
Copy link
Author

OK so how do I fix this I understand nothing of what you spoke about I just know the module could not delete user with the connect error.

I think for you there are 2 ways to approach this, which depend on you;

    • if you are not comfortable with coding in powershell, then you wait for rstolpe to re-write the code / or you look for another way to accomplish what you want to do.
    • you understand powershell coding enough to open the powershell function and I can show you why/where the problem is existing and what i did to make it work.

let me know.

@rstolpe
Copy link
Owner

rstolpe commented Apr 30, 2024

OK so how do I fix this I understand nothing of what you spoke about I just know the module could not delete user with the connect error.

I'll try to re-write it tomorrow, got some time in the morning.
Sorry for this bug.

@rstolpe
Copy link
Owner

rstolpe commented May 14, 2024

@DoubleJCream
@molitar

Hi,
I have added a pre-release now that should work. Please try it out.

To install it uninstall the old module first.

Uninstall-Module -Name "DeleteUserProfile" -Force

Then install the dependency module, it's req for the new version.

Install-Module -Name "rsServiceModule" -Scope AllUsers -Force

Then install the pre-release module

Install-Module -Name "DeleteUserProfile" -Scope AllUsers -AllowPrerelease -Force

Please confirm if it's working for you or not, I did just fix it up quickly and did a run with it.

@DoubleJCream
Copy link
Author

Hey rstolpe;
i just finished trying the beta and unfortunately it seems there is still an issue;

Confirm-RSProfile: Cannot validate argument on parameter 'Exclude'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.

i didn't have a lot of time to look at it but i'm guessing its the call to the function from;
Function Remove-RSUserProfile
-$CheckProfile = Confirm-RSProfile -UserName $UserNameFromPath -ProfileData $GetAllProfiles -Exclude $Exclude

But then in the function: Function Confirm-RSProfile
there is the validation;
[Parameter(Mandatory = $false, HelpMessage = "Enter the username you want to exclude from deletion")]
[ValidateNotNullOrEmpty()]
[String[]]$Exclude

Since my command was a simple delete;
Remove-RSUserProfile -ComputerName "puter" -UserName "gates.b"

there is no $Exclude variable defined but when it is passed to the Confirm-RSProfile, the variable $Exclude will be null which then is caught by [ValidateNotNullOrEmpty()]

my guess is that you would need two calls depending on if $Exclude is defined / or not, that or b option is to pull the [ValidateNotNullOrEmpty()] line but that could lead to other problems.

I'll leave this with you - let me know if i can do anything.

thanks

@rstolpe
Copy link
Owner

rstolpe commented May 17, 2024

Hey rstolpe;

i just finished trying the beta and unfortunately it seems there is still an issue;

Confirm-RSProfile: Cannot validate argument on parameter 'Exclude'. The argument is null or empty. Provide an argument that is not null or

empty, and then try the command again.

i didn't have a lot of time to look at it but i'm guessing its the call to the function from;

Function Remove-RSUserProfile

-$CheckProfile = Confirm-RSProfile -UserName $UserNameFromPath -ProfileData $GetAllProfiles -Exclude $Exclude

But then in the function: Function Confirm-RSProfile

there is the validation;

[Parameter(Mandatory = $false, HelpMessage = "Enter the username you want to exclude from deletion")]

    [ValidateNotNullOrEmpty()]

    [String[]]$Exclude

Since my command was a simple delete;

Remove-RSUserProfile -ComputerName "puter" -UserName "gates.b"

there is no $Exclude variable defined but when it is passed to the Confirm-RSProfile, the variable $Exclude will be null which then is caught by [ValidateNotNullOrEmpty()]

my guess is that you would need two calls depending on if $Exclude is defined / or not, that or b option is to pull the [ValidateNotNullOrEmpty()] line but that could lead to other problems.

I'll leave this with you - let me know if i can do anything.

thanks

Your totally right, to be honest I haven't had the time to look or the module yet.
I'll try to do it next week, crazy times at work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants