Query User Specific Registry Keys and Export to CSV

%3CLINGO-SUB%20id%3D%22lingo-sub-1031841%22%20slang%3D%22en-US%22%3EQuery%20User%20Specific%20Registry%20Keys%20and%20Export%20to%20CSV%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1031841%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20task%20to%20query%20the%20OneDrive%20HKCU%20registry%20key(HKCU%3A%5CSoftware%5CMicrosoft%5COneDrive%5CAccounts)%20and%20export%20those%20key%20properties%20and%20its%20values%20to%20some%20network%20location%20for%20evaluation%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20wrote%20a%20general%20PS%20script%20like%20below%20to%20do%20the%20job.%20And%20this%20needs%20to%20be%20executed%20only%20when%20user%20is%20logged%20in%20and%20in%20SCCM%20UserContext%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-ItemProperty%20-Path%20HKCU%3A%5CSoftware%5CMicrosoft%5COneDrive%5CAccounts%5CBusiness1%20-Name%20userfolder%2Cusername%2Cuseremail%20%7C%20Export-Csv%20%5Cabcd%5Cefgh%5Cijkl%5COneDrive.Csv%20-NoTypeInformation%20-Append%20-Force%0A%0AGet-ItemProperty%20-Path%20HKCU%3A%5CSoftware%5CMicrosoft%5COneDrive%5CAccounts%5CPersonal%20-Name%20userfolder%2Cusername%2Cuseremail%20%7C%20Export-Csv%20%5Cabcd%5Cefgh%5Cijkl%5COneDrive.Csv%20-NoTypeInformation%20-Append%20-Force%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3CSPAN%3Eif%20any%20users%20does%20not%20have%20those%20keys%20or%20properties%2C%20how%20to%20stop%20them%20from%20seeing%20some%20error%20message%20in%20PowerShell%20window%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1031841%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOneDrive%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1054489%22%20slang%3D%22en-US%22%3ERe%3A%20Query%20User%20Specific%20Registry%20Keys%20and%20Export%20to%20CSV%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1054489%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F346823%22%20target%3D%22_blank%22%3E%40Sri-Boddupalli%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eyou%20can%20try%20adding%20-ErrorAction%20SilentlyContinue%20to%20your%20Get-ItemProperty%20command%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

I have a task to query the OneDrive HKCU registry key(HKCU:\Software\Microsoft\OneDrive\Accounts) and export those key properties and its values to some network location for evaluation

 

So I wrote a general PS script like below to do the job. And this needs to be executed only when user is logged in and in SCCM UserContext

 

 

 

 

Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Business1 -Name userfolder,username,useremail | Export-Csv \abcd\efgh\ijkl\OneDrive.Csv -NoTypeInformation -Append -Force

Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name userfolder,username,useremail | Export-Csv \abcd\efgh\ijkl\OneDrive.Csv -NoTypeInformation -Append -Force

 

 

 

 if any users does not have those keys or properties, how to stop them from seeing some error message in PowerShell window?

1 Reply
Highlighted

@Sri-Boddupalli 

you can try adding -ErrorAction SilentlyContinue to your Get-ItemProperty command