Using PowerShell to Get SharePoint Content database size - powershell

What's the powershell command to get the all Content_DB size in SharePoint server(MB)?
Maybe?
Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name, #{Label ="Size in MB"; Expression = {$_.disksizerequired/1024/1024}}

If you need Export the report using below commands
Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name, #{Label ="Size in MB"; Expression = {$_.disksizerequired/1024/1024}} > c:\Content_DataBaseSize.txt

Related

Empty Value does not return

Get-VM |
Select Name, Operatingsystem, VMHost, PowerState,
#{N="Datastore"; E={$_ |
Get-Datastore}} |
Out-gridview
I ran this command. It will return and output a grid view with all rows filled in.
However, the field "OperatingSystem" returns a blank column, nothing there.
Untested, but I think you can do this:
Get-VM | Select-Object Name,
#{Name = 'Operatingsystem'; Expression = {$_.Guest.OsFullName}},
VMHost, PowerState,
#{Name = 'Datastore'; Expression = {$_ | Get-Datastore}} |
Out-GridView
You're looking for the "Guest" property I think. FYI you can also do this to view everything if you're not sure of the exact name
Get-VM |
Select-Object -Property * |
Out-gridview

How to access in this array of objects

I have this part of code -
$result = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, Publisher, InstallDate, UnistallString |
Where-Object InstallDate -GT 20180201 |
Where-Object UnistallDate -NotMatch " " |
Sort-Object -Property InstallDate -Descending |
Format-Table –AutoSize
$result
With the result of this command I get an array of objects, but if I try to access in it I get no result.
Example:
$result.UnisistallString. How can I access in it to get only the attributes of that parameter? Because with that then I need to print on video the name of the program and the unistall path.
You should not use the Format-Table cmdlet if you need to access the data in your code later. Also you have a typo in your example and the select statement. This should work:
$result = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, Publisher, InstallDate, UninstallString |
Where-Object InstallDate -GT 20180201 |
Sort-Object -Property InstallDate -Descending
Now Access it using:
$result.UninstallString

powershell out-file how to rid of extra spaces on each line

I run this command and I get all computer hostnames in the names.txt file.
Each hostname in the file is on a separate line, but every hostname is followed with white spaces which cause an issue when I try to read this file. How can I output to this file without getting the white spaces on each line?
Get-ADComputer -Filter * | Select-Object -property name | Sort-Object -Property name | out-file -filepath C:\temp\names.txt
You have the problem that you don't just have names, you have objects with the property 'name', and you also have the problem that Out-File runs complex objects through some kind of formatting before sending them to the file.
To fix both, expand the name out to just text, and generally use Set-Content instead:
Get-ADComputer -filter * | Select-Object -ExpandProperty Name | Sort-Object | Set-Content C:\temp\names.txt
or in short form
Get-ADComputer -filter * | Select -Expand Name | Sort | sc C:\temp\names.txt
or
(Get-ADComputer -filter *).Name | sort | sc C:\temp\names.txt
expandproperty should get rid of the #()
Get-ADComputer -Filter * | sort Name | Select -expandproperty Name | %{ $_.TrimEnd(" ") } | out-file -filepath C:\temp\names
Untested no AD#home
Piping it through this should work (before piping to the out-file):
EDIT: Piping through % { $_.name } should convert #{name=VALUE} to VALUE:
% { $_ -replace ' +$','' } | % { $_.name }
Like this:
Get-ADComputer -Filter * | Select-Object -property name | Sort-Object -Property name | % { $_ -replace ' +$','' } | % { $_.name } | out-file -filepath C:\temp\names.txt

How to get Export-Csv to output same information as screen output?

Get-WmiObject -list | where-object {$_.name -match "win32"} | Select-Object
name,methods,properties
This displays the name, methods and properties of each Win32 class and I wanted to get this information into a CSV file.
The following however outputs doesn't output the same information.
Get-WmiObject -list | where-object {$_.name -match "win32"} | Select-Object
name,methods,properties | Export-CSV "c:\output.csv"
How can I do this?
(Updated my script as it had an error.)
You need to do some extra manual work and make sure you expand the names and join them by some delimiter:
$methods = #{n='Methods';e={ ($_.Methods | select -expand Name) -join ';'}}
$properties = #{n='Properties';e={ ($_.Properties | select -expand Name) -join ';'}}
Get-WmiObject -List |
Where-Object {$_.Name -like "Win32_*"} |
Select-Object Name,$methods,$properties |
Export-Csv .\win32.csv -NoTypeInformation
The problem here is that each WMI Object has properties that themselves are arrays and Output-CSV can't really handle that.
To fix this, you'd need to handle the arrays of arrays explicitly.
WHat specifically do you want to be output?

Hashtable with Export-CSV

I am exporting data to a csv and for some reason the #{} are transferring over. Here is a sample script.
Get-VM VM | Select Name, #{N="DSFree";E={$_ | Get-Datastore | Select FreeSpaceMB }} | Export-Csv c:\temp\info.csv
The output of the DSFree column looks like this: #{FreeSpaceMB=686704}
How can I stop the #{} from exporting?
Thanks in advance.
I can't try your specific example, but typically -ExpandProperty is the answer:
Get-VM VM | Select Name, #{N="DSFree";E={$_ | Get-Datastore | Select -expandProperty FreeSpaceMB }} | Export-Csv c:\temp\info.csv
While #EBGreen's answer made me learn something, there is an easier way I believe in this case:
Get-VM VM | Select Name, #{N="DSFree";E={($_ | Get-Datastore).FreeSpaceMB }} | Export-Csv c:\temp\info.csv