Jean-Jacques CELMA
asked on
Powershell : xx AD inactive users within an OU with Office365 licences true
Dear Experts,
I have created that powershell script
add-type -assemblyName "Microsoft.VisualBasic"
$item = [Microsoft.VisualBasic.Int eraction]: :InputBox( "Enter number of days :", "List Inactive Users within xxx Days")
$OU = [Microsoft.VisualBasic.Int eraction]: :InputBox( "Enter OU (DN) :", "Distinguish Name")
Search-ADAccount -UsersOnly -SearchBase "$OU"-AccountInactive -TimeSpan $item | ?{$_.DistinguishedName -notmatch ‘OU=Spain,OU=Europe,OU=Roo t,DC=conto so,DC=com’ } | Get-ADUser -Properties Name, sAMAccountName, givenName, st, LastLogonDate, mail, userAccountControl, physicalDeliveryOfficeName | Where-Object {($_.userAccountControl -band 2) -eq $False} | Select-Object Name, sAMAccountName, givenName, LastLogonDate, st, mail, physicalDeliveryOfficeName , @{n='OU'; e={($_.distinguishedName -split ',OU=')[1]}} | Where {$_.OU -cnotlike "*Accounts" -and $_.OU -cnotlike "*Account"}
Import-Module MSOnline
$credential = get-credential
Connect-MsolService -Credential $credential
Get-MsolUser -UserPrincipalName $_.mail | where {$_.isLicensed -eq "True"} | Select-Object UserPrincipalName, FirstName, LastName, @{n='AccountSKUid'; e={$_.Licenses.AccountSKUi d}}, IsLicensed | Out-GridView
When I run it I am getting the following error
Get-MsolUser : Cannot bind argument to parameter « UserPrincipalName » because it is null.
Au caractère C:\powershell_scripts\Inac tive user account.ps1:8 : 33
+ Get-MsolUser -UserPrincipalName $_.mail | where {$_.isLicensed -eq "True"} | Sel ...
+ ~~~~~~~
+ CategoryInfo : InvalidData : (:) [Get-MsolUser], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nErrorNull NotAllowed ,Microsoft .Online.Ad ministrati on.Automat ion.GetUs
I have created that powershell script
add-type -assemblyName "Microsoft.VisualBasic"
$item = [Microsoft.VisualBasic.Int
$OU = [Microsoft.VisualBasic.Int
Search-ADAccount -UsersOnly -SearchBase "$OU"-AccountInactive -TimeSpan $item | ?{$_.DistinguishedName -notmatch ‘OU=Spain,OU=Europe,OU=Roo
Import-Module MSOnline
$credential = get-credential
Connect-MsolService -Credential $credential
Get-MsolUser -UserPrincipalName $_.mail | where {$_.isLicensed -eq "True"} | Select-Object UserPrincipalName, FirstName, LastName, @{n='AccountSKUid'; e={$_.Licenses.AccountSKUi
When I run it I am getting the following error
Get-MsolUser : Cannot bind argument to parameter « UserPrincipalName » because it is null.
Au caractère C:\powershell_scripts\Inac
+ Get-MsolUser -UserPrincipalName $_.mail | where {$_.isLicensed -eq "True"} | Sel ...
+ ~~~~~~~
+ CategoryInfo : InvalidData : (:) [Get-MsolUser], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
ASKER
Thks OBdA for the info and correction.
I have added @{n='Location'; e={$ADAccounts.PhysicalDel iveryOffic eName}}. But I got empty field in the list. It odes not display the physicalDeliveryOfficeName value of Get-ADuser.
Any clues?
Thks
JJC
$ADAccounts | ForEach-Object {
Get-MsolUser -UserPrincipalName $_.mail |
Where-Object {$_.isLicensed -eq "True"} |
Select-Object UserPrincipalName, FirstName, LastName, @{n='AccountSKUid'; e={$_.Licenses.AccountSKUid}}, IsLicensed , [b]@{n='Location'; e={$ADAccounts.PhysicalDeliveryOfficeName}}[/b]
} | Out-GridView
I have added @{n='Location'; e={$ADAccounts.PhysicalDel
Any clues?
Thks
JJC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
In the future, please use 'code' blocks when posting code (see the Tools bar directly above the input box).Edit: Fixed "pretty" single quotes in line 6.