Jump to content

Powershell Variable with $true in issue


Recommended Posts

Posted

I am trying to write a Powershell script where I create a variable with $true in it.

 

However I can not get the $ to display when the variable is called - as Powershell seems to think it is a variable and displays it as True

 

For example:

$variable1 = “New-ADUser abc -ChangePassword $true”

 

Calling the variable shows:

New-ADUser abc -ChangePassword True

 

So the command fail.

 

Can’t get it to work regardless of that quote marks I use

Posted

So @Cache is almost there and as you say @snagrat you can use 1 or 0, but just to cover this below is the way to stop powershell evaluating $ as a var note the backtick `.

 

$var1 = "test-aduser -identity abc1 -ChangePassword `$true"

 

below is a link that outlines the use of Special Characters:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters?view=powershell-7

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...