Automation

 View Only
  • 1.  Get all users for vms

    Posted Jul 13, 2010 11:36 PM

    I have an environment where users get added and removed from VMs quite frequently and I was looking for a way to get a list of what users are assigned to which VMs, preferably in csv or other delimited format that I can use to import into another program or spreadsheet to help in tracking this and I think that I can use PowerCLI to do this, but for the life of me can't figure out how. Here is a quick and dirty example of what I would like to achieve:

    VMName,Username,Role

    VM1,TestUser,Tester

    VM1,TestUser2,Supervisor

    VM2,TestUser2,Tester

    VM2,TestUser3,Analyst

    Any thoughts?



  • 2.  RE: Get all users for vms
    Best Answer

    Posted Jul 14, 2010 04:49 AM

    Try this perhaps

    $report = @()
    foreach($vm in Get-VM){
    	Get-VIPermission -Entity $vm | %{
    		$row = "" | Select VMName,Username,Role
    		$row.VMName = $vm.Name
    		$row.Username = $_.Principal
    		$row.Role = $_.Role
    		$report += $row
    	}
    }
    $repor | Export-Csv "C:\VM-roles.csv" -NoTypeInformationt
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: Get all users for vms

    Posted Jul 14, 2010 04:03 PM

    That was perfect! Thanks! The only issue was a small typo:

    $repor | Export-Csv "C:\VM-roles.csv" -NoTypeInformationt
    

    should have been

    $report | Export-Csv "C:\VM-roles.csv" -NoTypeInformation
    

    but no biggie :smileyhappy: