Link to home
Start Free TrialLog in
Avatar of MilesLogan
MilesLoganFlag for United States of America

asked on

Only update accounts with no data in certain fields v2

HI oBdA

I was trying to modify the script you gave me that does work to do what is below but man .. I cant get it ..

This works but it will update if data is there or not .. I want it to be like the other script you wrote
$Users = Import-Csv .\UpdateAccounttemplate.csv
foreach ($user in $users) {Set-QasUnixUser -identity $user.user_nuid -primarygidnumber $user.primary_gid -gecos $user.gecos }

Open in new window



I modified a few of the commands from what you originally created it for on the other question.

$Users = Import-Csv .\UpdateAccounttemplate.csv
$Users | ForEach-Object {
	"Processing '$($_.user_id)' ..." | Write-Host -ForegroundColor White
	If ($ADUser = Get-qasunixUser "samAccountName -eq '$($_.user_id)'" primarygidnumber, gecos) {
		$splat = @{'Identity' = $_.user_id}
		ForEach ($Property In 'primarygidnumber', 'gecos') {
			If ($ADUser.$Property) {
				"  - $($Property): '$($ADUser.$Property)'" | Write-Host -ForegroundColor White
			} Else {
				"  - $($Property): <empty>, will update" | Write-Host -ForegroundColor Yellow
				$splat[$Property] = $_.$Property
			}
		}
		If ($splat.Count -eq 1) {
			"... no update required." | Write-Host -ForegroundColor Green
		} Else {
			Try {
				Set-QasUnixUser @splat -ErrorAction Stop
				"... updated." | Write-Host -ForegroundColor Green
			} Catch {
				"Update failed: $($_.Exception.Message)" | Write-Host -ForegroundColor Red
			}
		}
	} Else {
		"... not found!" | Write-Host -ForegroundColor Red
	}
}

Open in new window



I get this error .
Get-QasUnixUser : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At C:\TESTING\Updatetemplate_v3.ps1:4 char:16
+ ...  ($ADUser = Get-qasunixUser "samAccountName -eq '$($_.user_id)'" prim ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-QasUnixUser], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Quest.AuthenticationServices.Commands.GetQasUnixUserCommand
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MilesLogan

ASKER

Man ! you so got it on the first try !!  I appreciate it .