I am building a HelpDesk app to change passwords, unlock accounts, etc.
On my Win10 or 2012 R2 systems (both with RSAT installed) I can manually run the below commands (substituting the variables with non GUI versions) but am unable to do so via the GUI.
When ran through the GUI I get the error that I posted below the commands. Is this a bug with PSS?
PowerShell version 5.1 and setting the build output to Windows Form 5.
--------------------------------------
$Identity = "$($outputSelected.Text)"
$Password = "$($inputPassword.Text)"
$SecPaswd = ConvertTo-SecureString -String $Password -AsPlainText -Force
$ADUser = Set-ADAccountPassword -Reset -Identity $Identity -NewPassword $SecPaswd -PassThru -Confirm:$false -WhatIf:$false -ErrorAction Stop
------------------------------------
new : The term 'new' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At \\iqfile\it\TECH\Apps\Development\HelpDesk\HelpDesk.Run.ps1:320 char:18
+ $output.Font = new Font("Serif", 48)
+ ~~~
+ CategoryInfo : ObjectNotFound: (new:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
new : The term 'new' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At \\iqfile\it\TECH\Apps\Development\HelpDesk\HelpDesk.Run.ps1:320 char:18
+ $output.Font = new Font("Serif", 48)
+ ~~~
+ CategoryInfo : ObjectNotFound: (new:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
ADAccountPassword will not work on Win10 or 2012R2 but will on 2008R2.
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- chrissmallwood
- Posts: 6
- Last visit: Fri Jan 05, 2024 7:34 am
Re: ADAccountPassword will not work on Win10 or 2012R2 but will on 2008R2.
It looks like you are trying to use C# code in PowerShell. Try using New-Object instead of new.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: ADAccountPassword will not work on Win10 or 2012R2 but will on 2008R2.
The correct syntax is:
$output.Font = [System.Drawing.Font]::New('Serif', 48)
or
$output.Font = New-Object System.Drawing.Font('Serif', 48)
or
$output.Font = 'Microsoft Sans Serif, 48pt'
$output.Font = [System.Drawing.Font]::New('Serif', 48)
or
$output.Font = New-Object System.Drawing.Font('Serif', 48)
or
$output.Font = 'Microsoft Sans Serif, 48pt'
- chrissmallwood
- Posts: 6
- Last visit: Fri Jan 05, 2024 7:34 am
Re: ADAccountPassword will not work on Win10 or 2012R2 but will on 2008R2.
I'm assuming that the error is in reference to the -NewPassword flag on the password change script as that is the only place that I am using "new." That being said, does that still line up with the suggested fix?
EDIT: OK, so I see what you are referring to with the font change. I'll go ahead and update that in the script. Can you give me some suggestions as to why the script won't change the password like it does if I run it manually in ISE?
EDIT: OK, so I see what you are referring to with the font change. I'll go ahead and update that in the script. Can you give me some suggestions as to why the script won't change the password like it does if I run it manually in ISE?
- chrissmallwood
- Posts: 6
- Last visit: Fri Jan 05, 2024 7:34 am
Re: ADAccountPassword will not work on Win10 or 2012R2 but will on 2008R2.
OK, not sure why but after I fixed the font issue earlier in the script it now changes the password as intended. I don't get it at all but I'm going to roll with it.
Thanks guys for your help!
Thanks guys for your help!
Re: ADAccountPassword will not work on Win10 or 2012R2 but will on 2008R2.
No. The error is very clear. Read the full error message. It clearly shows the line causing the error
The term 'new' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At \\iqfile\it\TECH\Apps\Development\HelpDesk\HelpDesk.Run.ps1:320 char:18
+ $output.Font = new Font("Serif", 48)
Line 320 is the cause.
The term 'new' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At \\iqfile\it\TECH\Apps\Development\HelpDesk\HelpDesk.Run.ps1:320 char:18
+ $output.Font = new Font("Serif", 48)
Line 320 is the cause.