Powershell command on domain computers as administrator

%3CLINGO-SUB%20id%3D%22lingo-sub-1340708%22%20slang%3D%22en-US%22%3EPowershell%20command%20on%20domain%20computers%20as%20administrator%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1340708%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20execute%20a%20command%20on%20all%20computers%20in%20my%20domain%20but%20in%20order%20for%20it%20to%20work%2C%20it%20needs%20to%20run%20with%20elevated%20permissions.%3C%2FP%3E%3CP%3EIs%20there%20a%20possibility%20to%20do%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Emy%20command%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eget-winevent%20-filterXML(%5Bxml%5D(Get-Content%20%22C%3A%5CExecute%5CInventorview.xml%22))%20%7C%20sort%20timecreated%20-descending%20%7C%20export-csv%20c%3A%5Cexecute%5Cresult.csv%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%3Ethe%20response%20i%20get%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eget-winevent%20%3A%20Could%20not%20retrieve%20information%20about%20the%20Security%20log.%20Error%3A%20Poging%20tot%20het%20uitvoeren%20van%20een%20niet-gema%0Achtigde%20bewerking..%0AAt%20line%3A1%20char%3A1%0A%2B%20get-winevent%20-filterXML(%5Bxml%5D(Get-Content%20%22C%3A%5CExecute%5CInventorview.xm%20...%0A%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0A%20%20%20%20%2B%20CategoryInfo%20%20%20%20%20%20%20%20%20%20%3A%20NotSpecified%3A%20(%3A)%20%5BGet-WinEvent%5D%2C%20Exception%0A%20%20%20%20%2B%20FullyQualifiedErrorId%20%3A%20LogInfoUnavailable%2CMicrosoft.PowerShell.Commands.GetWinEventCommand%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(Poging%20tot%20het%20uitvoeren%20van%20een%20niet-gemachtigde%20bewerking...%20%3D%20dutch%20for%20'trying%20to%20execute%20a%20non-authorized...')%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1340708%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDomain%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eget-winevent%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Egpo%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1362246%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20command%20on%20domain%20computers%20as%20administrator%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1362246%22%20slang%3D%22en-US%22%3E%3CP%3EHave%20you%20verified%20this%20command%20on%20a%20computer%20where%20you%20have%20administrator%20level%20access%3F%3CBR%20%2F%3EIf%20it%20provides%20the%20information%20you%20require%2C%20it's%20a%20matter%20of%20having%20admin%20access%20to%20all%20computers%20and%20launching%20PS%20under%20that%20user's%20context.%26nbsp%3B%3C%2FP%3E%3CP%3Eget-winevent%20has%20a%20-credential%20parameter%20you%20can%20use.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1374085%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20command%20on%20domain%20computers%20as%20administrator%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1374085%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F241399%22%20target%3D%22_blank%22%3E%40Animesh%20Joshi%3C%2FA%3E%26nbsp%3BI%20have%20verified%20this%20command%20with%20an%20admin%20account.%3C%2FP%3E%3CP%3ECan%20you%20run%20a%20scheduled%20task%20to%20all%20computers%20to%20run%20this%20script%20as%20an%20admin%3F%3C%2FP%3E%3CP%3EI'ts%20the%20first%20time%20that%20i'm%20trying%20anything%20like%20this%20so%20it's%20all%20kind%20of%20new%20for%20me.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi,

 

I want to execute a command on all computers in my domain but in order for it to work, it needs to run with elevated permissions.

Is there a possibility to do this?

 

my command:

 

get-winevent -filterXML([xml](Get-Content "C:\Execute\Inventorview.xml")) | sort timecreated -descending | export-csv c:\execute\result.csv

 

 

 

the response i get:

 

get-winevent : Could not retrieve information about the Security log. Error: Poging tot het uitvoeren van een niet-gema
chtigde bewerking..
At line:1 char:1
+ get-winevent -filterXML([xml](Get-Content "C:\Execute\Inventorview.xm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-WinEvent], Exception
    + FullyQualifiedErrorId : LogInfoUnavailable,Microsoft.PowerShell.Commands.GetWinEventCommand

 

 

 

(Poging tot het uitvoeren van een niet-gemachtigde bewerking... = dutch for 'trying to execute a non-authorized...')

 

Thanks in advance!

3 Replies

Have you verified this command on a computer where you have administrator level access?
If it provides the information you require, it's a matter of having admin access to all computers and launching PS under that user's context. 

get-winevent has a -credential parameter you can use.

@Animesh Joshi I have verified this command with an admin account.

Can you run a scheduled task to all computers to run this script as an admin?

I'ts the first time that i'm trying anything like this so it's all kind of new for me. 

 

 

Yes you can create a scheduled task to run on any number of remote computers as long as the user context under which the command is running has required access on the remote computer.