PowerShell cmdlets not working

PowerShell cmdlets not working

avatar

Hello,

I am starting to use the PowerShell cmdlets function in RDM, and have run into an issue. I am pretty sure I was able to use the New-RDMUser cmdlet yesterday, but now, in version 10.6.4.0, when I run the following: New-RDMUser -Name "user", I get the following error: New-RDMUser : Object reference not set to an instance of an object.

I am doing this inside of RDM using PowerShell (RDM CmdLet).

Not sure what I am missing here. I'll be happy to provide more information if necessary.

All Comments (12)

avatar

Hello,

You upgraded to 10.6.4 today?

Maurice

avatar

Yes, but this was also not working on 10.5.4.0 as well, so I updated in hopes that my issue would be resolved. I followed the same steps for installing the PSSnapin that was suggested on the online help document. That didn't seem to work.

When attempting to add a security group using New-RDMSecurityGroup, I get another error: WARNING: Your connection is not ready.

avatar

Just an update: I was able to get this to work inside the PowerShell (RDM Cmdlets) tool in RDM, but not able to launch the script inside an external PowerShell session. However, inside RDM, my script does not assign permissions to the group for the users I created. I will need to look over my script and see where I may be going wrong.

avatar

Another update: I have gotten users and security groups created. The only problem I am having now is with Set-RDMUserGroupRights. I am attempting to retrieve the data for a specific user and also for a group using the following code:

$user = Get-RDMUser | Where-Object {$_.Name -eq $student}
$group = Get-RDMSecurityGroup | Where-Object {$_.Name -eq $newstudentgroup}

$student and $newstudentgroup have the following values:

$student = rr\cnc1_user1
$newstudentgroup = CNC1_User1

The user account and the group both exist in the database:

PS C:\Program Files (x86)\Devolutions\Remote Desktop Manager> $user


CreateSQLServerLogin : False
IntegratedSecurity : False
Name : rr\cnc1_user1
OriginalName : rr\cnc1_user1
Password : System.Security.SecureString
PasswordSalt : WnRP8Z9pTH/0sVadYJTUiQ==
UserInfo : Devolutions.RemoteDesktopManager.Business.UserInfoRow
UserType : 0
CanAdd : False
CanAddCredentials :
CanAddDataEntry :
CanDelete : False
CanDeleteCredentials :
CanDeleteDataEntry :
CanEdit : False
CanEditCredentials :
CanEditDataEntry :
ConnectionOverrides :
CreationDate : 1/1/0001 12:00:00 AM
CustomSecurity :
DataSourceID : 00000000-0000-0000-0000-000000000000
Email :
FailedPasswordAttemptCount : 0
FailedPasswordAttemptWindowStart :
Description :
GroupInfos : {}
ID : 1d01aa3d-830b-4ecd-a42e-61024ac6b3a5
IsAdministrator : False
IsEnabled : True
IsLockedOut : False
IsNew : False
IsOwner : False
IsTemplate : False
LastLockoutDate :
LastLoginDate :
LastPasswordChangedDate :


PS C:\Program Files (x86)\Devolutions\Remote Desktop Manager> $group


CreationDate : 1/1/0001 12:00:00 AM
DataSourceID : 00000000-0000-0000-0000-000000000000
Description :
GroupInfo : Devolutions.RemoteDesktopManager.Business.GroupInfoRow
ID : ccbef852-d727-4af8-bf7b-a4829f6a7ebe
IsNew : False
Name : CNC1_User1
OriginalName : CNC1_User1


I keep getting this error: Set-RDMUserGroupRights : Cannot bind parameter 'User'. Cannot convert the "rr\cnc1_user1" value of type "System.String" to type "Devolutions.RemoteDesktopManager.Business.PS.PSUserInfo".

This is where I get stuck and am not sure how to get this to work.

avatar

here is my script, in case you're wondering:

$bgColor = 'Black'
$fgColor = 'White'
$textColor1 = 'DarkCyan'
$textColor2 = 'Cyan'
$textColor3 = 'Yellow'

function createRDMUsers {
#Get-PSSnapin -Name *Remote.Desktop* -Registered | % { Write-Host "$_..." -NoNewline; if ( (Get-PSSnapin -Name $_ -ErrorAction SilentlyContinue) -eq $null ) { Write-Host "installing" -ForegroundColor Yellow; Add-PsSnapin $_ } else { Write-Host "already installed" -ForegroundColor Green; } }
Add-PSSnapin Remote.Desktop.Manager.10.6.4

Start-Sleep -Seconds 5

$classdata = Import-Csv C:\Scripts\input\trsdeploy.csv | Where-Object {$_.Type -eq 'ClassData'}
$trsabbruser = $($classdata.TRSUser)
$classsize = $($classdata.Stations)
$dc1 = $($classdata.Site)


Write-Host -ForegroundColor $textColor2 "`nCreating RDM User accounts..."
$instructor = $dc1 + '\' + $trsabbruser + '_instructor'
$newrdminstructor = New-RDMUser -Name $instructor -IntegratedSecurity:$true -CreateSQLServerLogin:$true
Set-RDMuser $newrdminstructor
for( $i=1; $i -le $classsize; $i++ ) {
$dc1 = $($classdata.Site)
$newuser = $dc1 + '\' + $trsabbruser + '_user' + $i
$newrdmuser = New-RDMUser -Name $newuser -IntegratedSecurity:$true -CreateSQLServerLogin:$true
Set-RDMuser $newrdmuser
}
}

function createRDMSecurityGroups {
#Get-PSSnapin -Name *Remote.Desktop* -Registered | % { Write-Host "$_..." -NoNewline; if ( (Get-PSSnapin -Name $_ -ErrorAction SilentlyContinue) -eq $null ) { Write-Host "installing" -ForegroundColor Yellow; Add-PsSnapin $_ } else { Write-Host "already installed" -ForegroundColor Green; } }
Add-PSSnapin Remote.Desktop.Manager.10.6.4

Start-Sleep -Seconds 5

$classdata = Import-Csv C:\Scripts\input\trsdeploy.csv | Where-Object {$_.Type -eq 'ClassData'}
$trsabbruser = $($classdata.TRSUser)
$classsize = $($classdata.Stations)
$newinstructorgroup = $($trsabbruser.ToUpper()) + '_Instructor'
Write-Host -ForegroundColor $textColor2 "`nCreating RDM Instructor Security Group..."
$instructorsecgroup = New-RDMSecurityGroup -Name $newinstructorgroup
Set-RDMSecurityGroup $instructorsecgroup
$dc1 = $($classdata.Site)
$instructor = $dc1 + '\' + $trsabbruser + '_instructor'
$instructoruser = Get-RDMUser | Where-Object {$_.Name -eq $instructor}
$instructorgroup = Get-RDMSecurityGroup | Where-Object {$_.Name -eq $newinstructorgroup}

Write-Host -ForegroundColor $textColor2 "`nCreating RDM Student Security Groups and assigning users to those new groups..."
for( $i=1; $i -le $classsize; $i++ ) {

$dc1 = $($classdata.Site)
$student = $dc1 + '\' + $trsabbruser + '_user' + $i
$newstudentgroup = $($trsabbruser.ToUpper()) + '_User' + $i
$studentsecgroup = New-RDMSecurityGroup -Name $newstudentgroup
Set-RDMSecurityGroup $studentsecgroup

$user = Get-RDMUser | Where-Object {$_.Name -eq $student}
$group = Get-RDMSecurityGroup | Where-Object {$_.Name -eq $newstudentgroup}
Set-RDMUserGroupRights -User $user.Name -SecurityGroup $group -View
Set-RDMUserGroupRights -User $instructor.Name -SecurityGroup $group -View
}
}

createRDMUsers
createRDMSecurityGroups

Data is being pulled from a .csv file and I have validated that the data is being pulled correctly.

I am including the hardcoded variables to make this easier:

$trsabbruser = cnc1
$classsize = 4
$dc1 = rr

avatar

wow, lots of stuff to go through

Our powershell wiz will have a look at that on monday

Thank you for being so thorough, this is a nice script!

Maurice

avatar

I believe I have it working (only in RDM for now). Here is my modified script:

$bgColor = 'Black'
$fgColor = 'White'
$textColor1 = 'DarkCyan'
$textColor2 = 'Cyan'
$textColor3 = 'Yellow'

function setRDMSecurity {
#Get-PSSnapin -Name *Remote.Desktop* -Registered | % { Write-Host "$_..." -NoNewline; if ( (Get-PSSnapin -Name $_ -ErrorAction SilentlyContinue) -eq $null ) { Write-Host "installing" -ForegroundColor Yellow; Add-PsSnapin $_ } else { Write-Host "already installed" -ForegroundColor Green; } }
Add-PSSnapin Remote.Desktop.Manager.10.6.4

Start-Sleep -Seconds 5

#Create instructor security group.

$classdata = Import-Csv C:\Scripts\input\trsdeploy.csv | Where-Object {$_.Type -eq 'ClassData'}
$trsuserprefix = $($classdata.TRSUser)
$classsize = $($classdata.Stations)
$instructorgroupname = $($trsuserprefix.ToUpper()) + '_Instructor'

Write-Host -ForegroundColor $textColor2 "`nCreating RDM Instructor Security Group $instructorgroupname..."
$instructorsecgroup = New-RDMSecurityGroup -Name $instructorgroupname
Set-RDMSecurityGroup $instructorsecgroup

#Create instructor account.

$dc1 = $($classdata.Site)
$instructoracct = $dc1 + '\' + $trsuserprefix + '_instructor'

Write-Host -ForegroundColor $textColor2 "`nCreating instructor account $instructoracct..."
$newrdminstructor = New-RDMUser -Name $instructoracct -IntegratedSecurity -CreateSQLServerLogin

#Give instructor account rights on the instructor security group.

$instructorgroup = Get-RDMSecurityGroup | Where-Object {$_.Name -eq $instructorgroupname}
Write-Host -ForegroundColor $textColor2 "`nSetting permissions for $instructoracct on security group $instructorgroup..."
Set-RDMUserGroupRights -User $newrdminstructor -SecurityGroup $instructorgroup -View

Write-Host -ForegroundColor $textColor2 "`nSaving user $instructoracct..."
Set-RDMUser -User $newrdminstructor

#Create student security group, create student accounts, and assign rights to student security groups.

for( $i=1; $i -le $classsize; $i++ ) {
$studentgroupname = $($trsuserprefix.ToUpper()) + '_User' + $i
Write-Host -ForegroundColor $textColor2 "`nCreating RDM Instructor Security Group $studentgroupname..."
$studentsecgroup = New-RDMSecurityGroup -Name $studentgroupname
Set-RDMSecurityGroup $studentsecgroup

$studentacct = $dc1 + '\' + $trsuserprefix + '_user' + $i
Write-Host -ForegroundColor $textColor2 "`nCreating instructor account $studentacct..."
$newrdmstudent = New-RDMUser -Name $studentacct -IntegratedSecurity -CreateSQLServerLogin

$studentgroup = Get-RDMSecurityGroup | Where-Object {$_.Name -eq $studentgroupname}
Write-Host -ForegroundColor $textColor2 "`nSetting permissions for $instructoracct and $studentacct on security group $studentgroup..."
Set-RDMUserGroupRights -User $newrdminstructor -SecurityGroup $studentgroup -View
Set-RDMUserGroupRights -User $newrdmstudent -SecurityGroup $studentgroup -View

Write-Host -ForegroundColor $textColor2 "`nSaving user $studentacct..."
Set-RDMUser $newrdmstudent
}

}

setRDMSecurity

avatar

Sorry, I just realized that you have to move the following line down after the for loop:

Set-RDMUser -User $newrdminstructor

It wasn't setting permissions on the student groups for the instructor account and I just realized this a little too late.

Sorry about all of the posts, but I was hoping that this might help somebody else and save some time :-)

avatar

Well, I may have been a little premature in thinking this was working. Now for some reason, this is not working. I get the following error upon running the script: New-RDMSecurityGroup : Object reference not set to an instance of an object.

I know I had this working last week. Can someone please look at the script and tell me what I might be doing wrong here?

avatar

Sorry for so many posts here, but I think this may be helpful.

I think I may have figured out what my problem was. I was reading an article about having uninitialized variables that could cause this error, so I decided to initialize the $instructorsecgroup variable first. That seems to work now. I have since started initializing most of the variables but I'm still getting a null value somewhere, that I will work to figure out.

However, there may be a few bugs when executing commands. It's probably a lot to explain in the forum, but I would be happy to do a screen sharing session as I run these so you can see what is happening.

Setting permissions is not working as expected using the Set-RDMUserGroupRights cmdlet. Even though I only specify -View, it also adds the other 3 permissions to the user accounts.

I'll be running through the script a few more times and will let you know what else I can find.

avatar

OK, I have confirmed behavior that you guys might make sense of and I am suspecting I may be doing something wrong here.

When I create the new security group and give rights to the security group, I specify -View and leave out -Add, -Delete, and -Edit. Is it possible that those values default to $true and I need to include them with the $false switch? I'm going to try that and see if that solves that problem.

Otherwise, based on my current script, there is a value that is not being set on my $studentgroup variable when doing the Get-RDMSecurityGroup filtering by the group name. $studentgroup returns a null value except when it creates security groups for students 2, 3, and 4. I tried to do a Do/Until loop in case there is a delay, but that was just hanging the script.

I stopped the script and started it again, and everything processed correctly. I know the script is working because after it fails on the first iteration of the for loop, it works on all other security groups.

Again, something that someone might want to see happening live so that it makes more sense.

avatar

Could be a possible bug. No matter what I do for the Set-RDMUserGroupRights cmdlet, it gives all rights to the user instead of what is specified, regardless if I try the $false parameter on each one.