SOLVED

Powershell Scripts

%3CLINGO-SUB%20id%3D%22lingo-sub-1640265%22%20slang%3D%22de-DE%22%3EPowershell%20Scripts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1640265%22%20slang%3D%22de-DE%22%3EHello%2C%20%3CBR%20%2F%3E%3CBR%20%2F%3E%20i%20have%20a%20little%20question%20using%2Fcreating%20scripts%20in%20Powershell.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%20In%20my%20Company%20we%20use%20RegEdit.exe%20a%20lot%2C%20so%20we%20want%20to%20automate%20some%20things%2C%20that's%20where%20the%20problem%20starts...%20%3CBR%20%2F%3E%3CBR%20%2F%3E%20We%20want%20to%20disable%20the%20OneDrive%20shortcut%20in%20the%20MS-Explorer%20-%20I%20know%20that%20the%20path%20to%20do%20that%20manually%20is%20%22HKEY_USERS%22%5BSID%5D_Classes-CLSID-018D5C66-4533-4307-9B53-224DE2ED1FE6%22%20%3CBR%20%2F%3E%20I%20know%20how%20to%20get%20the%20SID%20via%20the%20cmdlet%20%3CBR%20%2F%3E%20%22System.Security.Principal.NTAccount(%24env%3AUsername).%20Translate(%5BSystem.Security.Principal.SecurityIdentifier%5D).%20Value%22%2C%20so%20my%20question%20now%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%20Is%20there%20a%20way%20to%20get%20the%20%5BSID%5D_Classes%20via%20a%20cmdlet%20or%20format%20the%20%22normal%22%20%5BSID%5D%20using%20an%20cmdlet%3F%20%3CBR%20%2F%3E%3CBR%20%2F%3E%20Greetings%20%3CBR%20%2F%3E%20Yannik%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1640265%22%20slang%3D%22de-DE%22%3E%3CLINGO-LABEL%3EPowershell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1640445%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20Scripts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1640445%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F784168%22%20target%3D%22_blank%22%3E%40Schulzi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHello%20Schulzi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20not%20aware%20of%20a%20cmdlet%2C%20but%20it%E2%80%99s%20quit%20easy%20to%20create%20the%20string%20you%20need%20by%20using%20string%20formatting.%20Take%20a%20look%20at%20this%20code%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24SID%20%3D%20(New-Object%20System.Security.Principal.NTAccount(%24env%3AUsername)).Translate(%5BSystem.Security.Principal.SecurityIdentifier%5D).Value%0A%24RegPath%20%3D%20'%22HKEY_USERS%22%7B0%7D_Classes-CLSID-018D5C66-4533-4307-9B53-224DE2ED1FE6%22'%20-f%20%24SID%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EMore%20info%20is%20here%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdevblogs.microsoft.com%2Fscripting%2Funderstanding-powershell-and-basic-string-formatting%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdevblogs.microsoft.com%2Fscripting%2Funderstanding-powershell-and-basic-string-formatting%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGood%20luck!%3C%2FP%3E%3CP%3EManfred%20de%20Laat%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1641116%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20Scripts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1641116%22%20slang%3D%22en-US%22%3EHello%20Manfred%2C%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20for%20the%20Quick%20Help%2C%20really%20helped%20me%20do%20my%20work.%3CBR%20%2F%3E%3CBR%20%2F%3EGreetings%3CBR%20%2F%3EYannik%20Schulz%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor
Hello,

i have a little question using/creating scripts in Powershell.

In my Company we use RegEdit.exe a lot, so we want to automate some things, that's where the Problem starts...

We want to disable the OneDrive shortcut in the MS-Explorer - I know that the path to do that manually is "HKEY_USERS\[SID]_Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}
I know how to get the SID via the cmdlet
"System.Security.Principal.NTAccount($env:Username).Translate([System.Security.Principal.SecurityIdentifier]).Value", so my question now:

Is there a way to get the [SID]_Classes via a cmdlet or format the "normal" [SID] using an cmdlet?

Greetings
Yannik
2 Replies
Highlighted
Best Response confirmed by Schulzi (Occasional Contributor)
Solution

@Schulzi 

Hello Schulzi,

 

I am not aware of a cmdlet, but it’s quit easy to create the string you need by using string formatting. Take a look at this code:

$SID = (New-Object System.Security.Principal.NTAccount($env:Username)).Translate([System.Security.Principal.SecurityIdentifier]).Value
$RegPath = '"HKEY_USERS"{0}_Classes-CLSID-018D5C66-4533-4307-9B53-224DE2ED1FE6"' -f $SID

More info is here:

https://devblogs.microsoft.com/scripting/understanding-powershell-and-basic-string-formatting/

 

Good luck!

Manfred de Laat

 

 

 

Highlighted
Hello Manfred,

Thanks for the Quick Help, really helped me do my work.

Greetings
Yannik Schulz