MilesLogan
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
I modified a few of the commands from what you originally created it for on the other question.
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 : PositionalParameterNotFoun d,Quest.Au thenticati onServices .Commands. GetQasUnix UserComman d
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 }
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
}
}
I get this error .
Get-QasUnixUser : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At C:\TESTING\Updatetemplate_
+ ... ($ADUser = Get-qasunixUser "samAccountName -eq '$($_.user_id)'" prim ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-QasUnixUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFoun
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER