Tag: Export-CSV

PS (Unfinished): O365 User Exporter For MaaS360

PS (Unfinished): O365 User Exporter For MaaS360

Image result for its broken meme

#############################################
## Global Varibles
#############################################
$script:SelectedPath = $null
$script:PrimaryDomain = $null
$script:PulledUserData = $null
$Script:date = Get-Date -Format ddmmyyhhmm
#############################################
## Functions
#############################################
Function EnvConfiguration () {
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -ErrorAction Stop
Add-Type -AssemblyName PresentationFramework
Add-Type -assemblyName PresentationCore
Add-Type -assemblyName WindowsBase
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
}
Function WelcomeDialouge () {
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OKCancel
$MessageIcon = [Windows.MessageBoxImage]::Information
$MessageTitle = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "Welcome to the O365 Exporter Tool for`nMass User Importation into MaaS360`n `nScript Developed By: Daisy Olivia Stevens`nhttps://adminscriptbank.wordpress.com`nhttps://www.linkedin.com/in/theheroic"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){ConnectO365}
}
Function ConnectO365 (){
# Obtain Creds from User input and then connect to Office 365
Connect-MsolService #-ErrorAction stop
# Move to the next function
Set-DestinationPath
}
function Set-DestinationPath {
$Message = "Please select a directory for your exported data"
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{SelectedPath = 'C:\'}
$FolderBrowser.Description = $Message
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath
if ($FolderBrowser.SelectedPath -eq $null){
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OKCancel
$MessageIcon = [Windows.MessageBoxImage]::Error
$MessageTitle = "ASB -- O365 CSV Exporter For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "No Path Was Selected!`nDo you wish to try again?"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){Set-DestinationPath} else {exit}
}
$script:SelectedPath = $FolderBrowser.SelectedPath
PrimaryDomainSelector
}
Function PrimaryDomainSelector {
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$objForm.Size = New-Object System.Drawing.Size(800,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objListBox.SelectedItem;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close();PullUserData;})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please Select Your Primary Domain:"
$objForm.Controls.Add($objLabel)
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Size(10,40)
$objListBox.Size = New-Object System.Drawing.Size(755,20)
$objListBox.Height = 80
Get-MsolDomain | Select-Object name | ForEach-Object {$_.Name | Add-Content -Path .\o365Domains.tmp}
ForEach($i in (Get-Content .\o365Domains.tmp))
{[void] $objListBox.Items.Add($i)}
$objForm.Controls.Add($objListBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$script:PrimaryDomain = $objListBox.SelectedItem
$FileName = ".\o365Domains.tmp"
if (Test-Path $FileName)
{
Remove-Item $FileName
}
}
function PullUserData {
$script:PulledUserData = Get-MsolUser -All | Select-Object *
ComposeCSV
}
function CustomInputBox([string] $title, [string] $message, [string] $defaultText) {
[void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$userForm = New-Object System.Windows.Forms.Form
$userForm.Text = "$title"
$userForm.Size = New-Object System.Drawing.Size(800,200)
$userForm.StartPosition = "CenterScreen"
$userForm.AutoSize = $False
$userForm.MinimizeBox = $False
$userForm.MaximizeBox = $False
$userForm.SizeGripStyle= "Hide"
$userForm.WindowState = "Normal"
$userForm.FormBorderStyle="Fixed3D"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(115,80)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$value=$objTextBox.Text;$userForm.Close()})
$userForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(195,80)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$userForm.Close()})
$userForm.Controls.Add($CancelButton)
$userLabel = New-Object System.Windows.Forms.Label
$userLabel.Location = New-Object System.Drawing.Size(10,20)
$userLabel.Size = New-Object System.Drawing.Size(280,20)
$userLabel.Text = "$message"
$userForm.Controls.Add($userLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objTextBox.Text="$defaultText"
$userForm.Controls.Add($objTextBox)
$userForm.Topmost = $True
$userForm.Opacity = 1.0
$userForm.ShowIcon = $False
$userForm.Add_Shown({$userForm.Activate()})
[void] $userForm.ShowDialog()
$value=$objTextBox.Text
return $value
}
function ComposeCSV {
$UserInputTitle = "ASB -- O365 CSV Exporter For IBM MaaS360 -- Daisy Stevens"
$userInputText = "Please enter your international country code: "
$UserInputDText = "+44"
$userInput = CustomInputBox $UserInputTitle $userInputText $UserInputDText
if ($userInput -eq $null){
$userInput = CustomInputBox $UserInputTitle $userInputText $UserInputDText
}
$Data = New-Object System.Object
$Data | Add-Member -MemberType Property -Name "Full Name" -Value $script:PulledUserData.DisplayName
$Data | Add-member -MemberType Property -Name "User Name" -Value $script:PulledUserData.Signinname
$Data | Add-Member -MemberType Property -Name "Domain" -Value $Domain
$Data | Add-Member -MemberType Property -Name "Email" -Value $script:PulledUserData.signinname
$Data | Add-Member -MemberType Property -Name "Phone Number Country" -Value $userInput
$Data | Add-Member -MemberType Property -Name "Phone Number" -Value $script:PulledUserData.PhoneNumber
$Data | Add-Member -MemberType Property
-Name "Location" -Value "London"
$Data | add-member -MemberType Property -Name "Auth Type" -Value "Local"
$Data | select * | Export-Csv -Path "$script:SelectedPath\Maas360_Export_$script:date.csv" -NoTypeInformation
CompleteMSG
}
function CompleteMSG {
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OK
$MessageIcon = [Windows.MessageBoxImage]::Information
$MessageTitle = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "The Script has completed successfully"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){exit}
}
#############################################
## Function Calls
#############################################
EnvConfiguration
WelcomeDialouge
Advertisements
PowerCLI: Memory Usage Report Script

PowerCLI: Memory Usage Report Script

The Below one liner will generate a CSV file containing the following

  • VM Host
  • VM Folder
  • VM Name
  • VM Memory Allocation
  • VM Memory Average Usage Last 30 Days
PowerCLI C:\> get-vm | Where {$_.PowerState -eq "PoweredOn"} | sort Name | Select-Object VMHost,Folder,Name,MemoryGB,@{N="Memory Usage (Average Over 30 Days), %" ; E={[Math]::Ro
und((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} | Format-Table -autosize -Property VMho
st,Folder,Name,MemoryGB,"Memory Usage (Average Over 30 Days), %" | Export-Csv C:\temp\MemoryUsage.CSV
PowerCLI: SAN Usage Report

PowerCLI: SAN Usage Report

 

Okay, today I have been tasked to find out where all of our storage has gone and because this SAN LUN is shared between a multiple of systems I have decided to generate the report based on Folder size within the LUN. Please see below for the script to run from PowerCLI

$searchSpec1 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec1.details = New-Object VMware.Vim.FileQueryFlags
$searchSpec1.details.fileSize = $true
$searchSpec1.query += New-Object VMware.Vim.FolderFileQuery
$searchSpec2 = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec2.details = New-Object VMware.Vim.FileQueryFlags
$searchSpec2.details.fileSize = $true
$searchSpec2.query += New-Object VMware.Vim.FileQuery
$report = @()
Get-Datastore | Get-View | % {
$browser = Get-View -Id ($_.Browser)
$dsPath = "[" + $_.Summary.Name + "] /"
$folderList = $browser.SearchDatastore($dsPath, $searchSpec1)foreach($folder in $folderList.File){
$folderPath = $dsPath + $folder.Path
$fldresult = $browser.SearchDatastore($folderPath, $searchSpec2)
$fldSize = 0
foreach($file in $fldresult.File){$fldSize += $file.FileSize}
$row = "" | select DSName, FolderName, FolderSize
$row.DSName = $folderList.FolderPath
$row.FolderName = $folder.Path
$row.FolderSize = $fldSize
$report += $row
}
}
$report | Export-Csv "c:\powershell\Foldersize.csv" -noTypeInformation

Once you have harvested your CSV import it into excel and use the following on the custom format for file size

[<500000]#,##0" B ";[<500000000]#,##0,," MB";#,##0,,," GB"