K
K
Konstantin2018-04-25 09:36:28
PowerShell
Konstantin, 2018-04-25 09:36:28

How to use variable in Powershell with text "_Classes"?

Hey!
I'm gaining experience with Powershell, but I can't find the answer to my question. The bottom line is this:
There is a script that gets the user's SID

$CurrentUser = Read-host "Name of current user"
$objUser = New-Object System.Security.Principal.NTAccount($CurrentUser)
$CurrentUserSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])

And after that, a file should be generated where this variable will be used:
Write-Output "\Registry\USER\$CurrentUserSID\SOFTWARE\
\Registry\USER\$CurrentUserSID_Classes\SOFTWARE\" > file.txt
The problem occurs with $CurrentUserSID_Classes . As far as I understand, this is perceived not as a $CurrentUserSID variable with the text _Classes, but as a $CurrentUserSID_Classes
variable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2018-04-25
@fallen8rwtf

"\Registry\USER\$CurrentUserSID\SOFTWARE\
\Registry\USER\$CurrentUserSID" + "_Classes\SOFTWARE\" > file.txt
just remove write-output and stick _Classes...
or like this:
Write-Output "\Registry \USER\$CurrentUserSID\SOFTWARE\
\Registry\USER\$($CurrentUserSID)_Classes\SOFTWARE\" > file.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question