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
LVL 2
MilesLoganAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Can't test the Qas-cmdlets, and I couldn't find a full syntax description online, so I have to by feel here.
One thing is that the user id column in this csv seems to be called user_nuid, according to your first, working, code snippet.
Then the Qas cmdlets have a different syntax than the default AD cmdlets, and the trick with properties loop was based on the column names having the same name as the cmdlet arguments.
Try below, and in the UpdateAccounttemplate.csv, change the column primary_gid to primarygidnumber so that it matches the argument/property; gecos can stay as it is.
$Users = Import-Csv .\UpdateAccounttemplate.csv
$Users | ForEach-Object {
	"Processing '$($_.user_nuid)' ..." | Write-Host -ForegroundColor White
	Try {
		$QASUser = Get-QasUnixUser -Identity $_.user_nuid -ErrorAction Stop
		$splat = @{'Identity' = $_.user_nuid}
		ForEach ($Property In 'primarygidnumber', 'gecos') {
			If ($QASUser.$Property) {
				"  - $($Property): '$($QASUser.$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
			}
		}
	} Catch {
		"... not found: $($_.Exception.Message)" | Write-Host -ForegroundColor Red
	}
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MilesLoganAuthor Commented:
Man ! you so got it on the first try !!  I appreciate it .
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.