Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Powershell Ruan As Administrator

$
0
0

This line should give you what you need:
Get-WmiObject -Class Win32_ComputerSystem | select * | Out-File ($env:COMPUTERNAME + ".txt")

To make this runs as administrator, on this or any machine, whether they're on the same domain or not, you can use something like:

$DomainAccount = "domain\user-with-eoungh-permissions-for-task"
    $Targets = @("PC1","PC2","PC3") # or get Target computer list from AD, or network scan, or…
    #
    if (!(Test-Path -Path ".\DomainCred.txt")) {
        Write-Output "Error: missing encrypted pwd file .\DomainCred.txt, enter the pwd to be encrypted and saved to .\DomainCred.txt for future script use:" 
        Read-Host 'Enter the pwd to be encrypted and saved to .\DomainCred.txt for future script use:' -AsSecureString | ConvertFrom-SecureString | Out-File .\DomainCred.txt
    }
    $Pwd = Get-Content .\DomainCred.txt | ConvertTo-SecureString
    $DomainCred = New-Object System.Management.Automation.PSCredential($DomainAccount,$Pwd)
    foreach ($Computer in $Targets) {
        $PC = Invoke-Command -ComputerName $Computer -Credential $DomainCred -ScriptBlock { 
            $data = Get-WmiObject -Class Win32_ComputerSystem | select *
            return $data
        } 
        $PC | Out-File ($Computer + ".txt")
    }
Attachments:
You must be logged in to view attached files.

Viewing all articles
Browse latest Browse all 13067

Trending Articles