Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Cannot convert 'System.Object[]' to the type 'System.Nullable'1[System.Boolean\' required by parameter 'Enabled'

$
0
0

Hi all, extremely new to powershell. I am getting the error "Cannot convert 'System.Object[]' to the type 'System.Nullable'1[System.Boolean\' required by parameter 'Enabled'" when I call a function.

Function Disable-InactiveComputer { $iComputers = Get-ADComputer -Filter {(LastLogonDate -le $disableD) -and (PasswordLastSet -le $disableD)} -SearchBase $desktopOU -Properties * | ?{$_.LastLogonDate -ne $null} $filePath2 = Get-Date -uformat ($folderPath + "Computer_Account_Disabled_on_%d%m%Y.csv") if ($iComputers){ Foreach($iComputer in $iComputers){ Set-ADComputer -Enabled $false, -Description "Auto Disabled on $(Get-Date -format 'D')" ` | Move-ADObject -TargetPath $disabledOU -PassThru ` $cpt = Get-ADComputer $($iComputer.Name) -properties * | Sort-Object LastLogonDate -descending $props = @{ ‘ComputerName’=$cpt.Name; ‘Description’=$cpt.Description; ‘OSVersion’=$cpt.OperatingSystem; ‘SPVersion’=$cpt.OperatingSystemServicePack; ‘LastLogonDate’=$cpt.LastLogonDate} $obj = New-Object -TypeName PSObject -Property $props $tobj += $obj } $tobj | Select-Object ComputerName, Description, OSVersion, SPVersion, LastLogonDate | Sort-Object Name | Export-Csv $filePath2 -NoTypeInformation } }

The variables are:

$folderPath = "$env:WINDIR\Temp\"
$idays = 360
$ddays = 720
$disableD = (Get-Date).AddDays(-($idays))
$deleteD = (Get-Date).AddDays(-($ddays))
$desktopOU = "OU=DistinguishedName,DC=test,DC=com"
$disabledOU = "OU=DistinghuishedName,DC=test,DC=com"
$tobj = @()

The .csv file gets created with the correct file name, in the correct location, but the computer object doesn't get disabled, does not set the description, and it does not get moved to $disableDOU

I'd very much appreciate any assistance, thank you.



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>