snagrat Posted September 22, 2020 Posted September 22, 2020 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
Cache Posted September 22, 2020 Posted September 22, 2020 Try $variable1 = “New-ADUser abc -ChangePassword '$true”
snagrat Posted September 24, 2020 Author Posted September 24, 2020 In the end I figured out you can use $true or 1, and also $false or 0. So that got it sorted.
HPlum78 Posted September 25, 2020 Posted September 25, 2020 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now