How to set the size of Page File on Windows(pagefile.sys) via PowerShell?
This is how we can update the size of pagefile.sys via PowerShell:
# PowerShell Script to set the size of pagefile.sys
$computersys = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges;
$computersys.AutomaticManagedPagefile = $False;
$computersys.Put();
$pagefile = Get-WmiObject -Query "Select * From Win32_PageFileSetting Where Name like '%pagefile.sys'";
$pagefile.InitialSize = <New_Value_For_Size_In_MB>;
$pagefile.MaximumSize = <New_Value_For_Size_In_MB>;
$pagefile.Put();
Execute the script as below:
PS> .\update_pagefile_size.ps1;
HERE is the solution
THIS is to set C VOL page file to 16384MB, static and D VOL page file to System managed:
# PowerShell Script to set the size of pagefile.sys
# update_pagefile_size.ps1
$pagefile = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges
$pagefile.AutomaticManagedPagefile = $false
#$pagefile.put() | Out-Null
Gwmi win32_pagefilesetting | where{$_.caption -like 'C:*'}
$pagefileset = Gwmi win32_pagefilesetting | where{$_.caption -like 'C:*'}
$pagefileset.InitialSize = 16384
$pagefileset.MaximumSize = 16384
$pagefileset.Put() | Out-Null
if((Set-WmiInstance -Class Win32_PageFileSetting -Arguments #{name="C:\pagefile.sys";InitialSize = $pagefileset.InitialSize; MaximumSize = $pagefileset.MaximumSize} -EnableAllPrivileges -Verbose) -icontains "already exists"){
$pagefileset = Gwmi win32_pagefilesetting | where{$_.caption -like 'C:*'}
$pagefileset.Delete()
$pagefileset.InitialSize = 16384
$pagefileset.MaximumSize = 16384
Set-WmiInstance -Class Win32_PageFileSetting -Arguments #{name="C:\pagefile.sys";InitialSize = $pagefileset.InitialSize; MaximumSize = $pagefileset.MaximumSize} -EnableAllPrivileges
Gwmi win32_pagefilesetting | where{$_.caption -like 'C:*'}
}
$pagefileset = Gwmi win32_pagefilesetting | where{$_.caption -like 'D:*'}
$pagefileset.InitialSize = 0
$pagefileset.MaximumSize = 0
$pagefileset.Put() | Out-Null
Gwmi win32_pagefilesetting | where{$_.caption -like 'D:*'}
Set-WmiInstance -Class Win32_PageFileSetting -Arguments #{name="D:\pagefile.sys";InitialSize = 0; MaximumSize = 0} -EnableAllPrivileges | Out-Null
Write-host "Don't forget to reboot"
#shutdown /r /t 120 /c "rebooting to fix pagefile"
Well, to GET the pagefile with Powershell use this function I got from Mike Kanakos: "function-getpagefilessize.ps1", which, for some reason, does not work from the profile as a PS file or PSM file:
Function Get-PageFileInfo {
<#
.Synopsis
Returns info about the page file size of a Windows computer. Defaults to local machine.
.Description
Returns the pagefile size info in MB. Also returns the PageFilePath, PageFileTotalSize, PagefileCurrentUsage,
and PageFilePeakusage. Also returns if computer is using a TempPafeFile and if the machine's pagefile is
managed by O/S (AutoManaged = true) or statically set (AutoManaged = False)
.Example
Get-PageFileInfo -computername SRV01
Returns pagefile info for the computer named SRV01
Computer : SRV01
FilePath : C:\pagefile.sys
AutoManagedPageFile : True
TotalSize (in MB) : 8192
CurrentUsage (in MB) : 60
PeakUsage (in MB) : 203
TempPageFileInUse : False
.Example
Get-PageFileInfo SRV01, SRV02
Returns pagefile info for two computers named SRV01 & DC02.
Computer : SRV01
FilePath : C:\pagefile.sys
AutoManagedPageFile : True
TotalSize (in MB) : 8192
CurrentUsage (in MB) : 60
PeakUsage (in MB) : 203
TempPageFileInUse : False
Computer : SRV02
FilePath : C:\pagefile.sys
AutoManagedPageFile : True
TotalSize (in MB) : 8192
CurrentUsage (in MB) : 0
PeakUsage (in MB) : 0
TempPageFileInUse : False
.Example
Get-PageFileInfo SRV01, SRV02, SRV03 | Format-Table
Returns pagefile info for three computers named SRV01, SRV02 & SRV03 in a table format.
Computer FilePath AutoManagedPageFile TotalSize (in MB) CurrentUsage (in MB) PeakUsage (in MB) TempPageFileInUse
-------- -------- ------------------- ----------------- -------------------- ----------------- -----------------
SRV01 C:\pagefile.sys True 8192 60 203 False
SRV02 C:\pagefile.sys True 13312 0 0 False
SRV03 C:\pagefile.sys True 2432 0 0 False
.Parameter computername
The name of the computer to query. Required field.
.Notes
NAME: Get-PageFileInfo
AUTHOR: Mike Kanakos
Version: v1.1
LASTEDIT: Thursday, August 30, 2018 2:19:18 PM
.Link
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[string[]]$ComputerName
)
# Main Part of function
Foreach ($computer in $ComputerName)
{
$online= Test-Connection -ComputerName $computer -Count 2 -Quiet
if ($online -eq $true)
{
$PageFileResults = Get-CimInstance -Class Win32_PageFileUsage -ComputerName $Computer | Select-Object *
$CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2'
$PageFileStats = [PSCustomObject]#{
Computer = $computer
FilePath = $PageFileResults.Description
AutoManagedPageFile = $CompSysResults.AutomaticManagedPagefile
"TotalSize(in MB)" = $PageFileResults.AllocatedBaseSize
"CurrentUsage(in MB)" = $PageFileResults.CurrentUsage
"PeakUsage(in MB)" = $PageFileResults.PeakUsage
TempPageFileInUse = $PageFileResults.TempPageFile
} #END PSCUSTOMOBJECT
} #END IF
else
{
# Computer is not reachable!
Write-Host "Error: $computer not online" -Foreground white -BackgroundColor Red
} # END ELSE
$PageFileStats
} #END FOREACH
} #END FUNCTION
#AUTHOR: Mike Kanakos#
But setting the page file then runs into ALL kinds of issues. Like, it gets REAL buggy. IF it is set you can change it, if it is not, you must first set to system managed and then set to something, like 16384/16384 on C and System managed on D:.
I am working on the answer myself, because I need this, and I will get back to ya'll when I get it sorted (amongst my long list of other scripts to do)...
But, ITMT, the function will help. Do a ForEach to a list like this:
remove-item -Force volumeletter:\folder\outputfile.txt
$results = (Get-PageFileInfo -Verbose server1.domain,server2.domain |select * |format-table -AutoSize)
$results |out-file volumeletter:\folder\outputfile.txt -Force ascii
OR you load up the Function in ISE, run it to load into memory and then query each server manually from the PS cmd:
Get-PageFileInfo server1.domain
Computer : server1.domain
FilePath : {C:\pagefile.sys, D:\pagefile.sys}
AutoManagedPageFile : False
TotalSize(in MB) : {16384, 768}
CurrentUsage(in MB) : {88, 62}
PeakUsage(in MB) : {120, 84}
TempPageFileInUse : {False, False}
You will see blanks if you are required to use FQDN...
IF you have the standard system managed the function will give you the usage, and that will tell you if you have to set the static sizes:
Get-PageFileInfo server2.domain
Computer : server2.domain
FilePath : C:\pagefile.sys
AutoManagedPageFile : True
TotalSize(in MB) : 7679
CurrentUsage(in MB) : 1763
PeakUsage(in MB) : 4867
TempPageFileInUse : False
For newer versions of PowerShell:
Starting in PowerShell 3.0, the Get-WmiObject cmdlet has been superseded by Get-CimInstance.
$PageFile = Get-CimInstance -ClassName Win32_PageFileSetting -Filter "Name like '%pagefile.sys'"
$PageFile | Remove-CimInstance
$PageFile = New-CimInstance -ClassName Win32_PageFileSetting -Property #{ Name= "C:\pagefile.sys" }
$PageFile | Set-CimInstance -Property #{ InitialSize = 0; MaximumSize = 0 }
Note: you will need administrator privileges to change the pagefile.
Related
I'm new to scripting so please excuse me if my script is messy. This script pretty much does what I want it to do but for 2 fields it doesn't return the values.
If I run the commands without Invoke I get all the values I want but when I run this with the Invoke command on remote computers the OsHotFixes and CsProcessors return weird values of "Microsoft.PowerShell.Commands.HotFix" for each hotfix and "Microsoft.PowerShell.Commands.Processor" for the CsProcessors value. All other properties gave me the values I am looking for. I'm not sure why those 2 aren't returning correct values. If someone could point me in the right direction that would be awesome.
$c = Get-Content "myfilepath"
$e = "myfilepath"
$ScriptBlock = {
$ComputerInfo = Get-ComputerInfo -Property WindowsVersion, OsBuildNumber, OsHotFixes, CsModel, BiosSMBIOSBIOSVersion, WindowsProductName, CsProcessor, OsInstallDate, OsArchitecture, CsProcessors
$GPU = Get-WmiObject win32_VideoController | Select-Object "Name", "DeviceID", "DriverVersion"
$RAM = Get-CimInstance -ClassName CIM_PhysicalMemory | Select-Object "Manufacturer", "PartNumber", #{'Name'='Capacity (GB)'; 'Expression'={[math]::Truncate($_.capacity / 1GB)}}, "Speed"
$Storage = Get-WmiObject Win32_LogicalDisk | Where caption -eq "C:" | Foreach-object {write " $($_.caption) $('{0:N2}' -f ($_.Size/1gb)) GB total, $('{0:N2}' -f ($_.FreeSpace/1gb)) GB Free"}
$MyArray = #($ComputerInfo, $GPU, $RAM, $Storage)
$Properties =
#(
'WindowsVersion'
'OsBuildNumber'
'OsHotFixes'
'CsModel'
'BiosSMBIOSBIOSVersion'
'WindowsProductName'
'OsInstallDate'
'OsArchitecture'
'CsProcessors'
'Name'
'DeviceID'
'DriverVersion'
'Manufacturer'
'PartNumber'
'Capacity'
'Speed'
'Disk'
)
$MyArray | ForEach-Object {
:Inner ForEach( $Property in $Properties )
{
If($_.$Property)
{
[PSCustomObject][Ordered]#{
hostname = $env:COMPUTERNAME
WindowsVersion = $_.WindowsVersion
Build = $_.OsBuildNumber
Patches = $_.OsHotFixes
Motherboard = $_.CsModel
BiosVersion = $_.BiosSMBIOSBIOSVersion
WindowsProductName = $_.WindowsProductName
OsInstallDate = $_.OsInstallDate
OsArchitecture = $_.OsArchitecture
Processor = $_.CsProcessors
GPUName = $_.Name
DeviceID = $_.DeviceID
DriverVersion = $_.DriverVersion
RamManufacturer = $_.Manufacturer
PartNumber = $_.PartNumber
Capacity = $_.Capacity
Speed = $_.Speed
Disk = $Storage
}
Break Inner
}
}
}
}
Invoke-Command -ComputerName $c -ScriptBlock $ScriptBlock | Sort hostname | Export-Csv -append $e -NoTypeInformation
I've tried running just the lines from 4 - 8 locally and then Outputting the Array. This will show all correct values. However when this script runs with the PSCustomObject and Invoke command I don't get CsProcessors or OsHotFixes values.
I wonder if you could help me out guys.
I need to stop a powershell script if the disk size of partition E is less than 10GB, and to continue if it´s more than 10GB.
So far i managed to get my disk size listed with this.
Get-WmiObject -Class win32_logicaldisk | Format-Table DeviceId,#{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}
And i get this result:
DeviceId
Freespace
A
0
C
77.9
D
0
E
34.05
So, i want to stop the powershell script if E unit has less than 10GB.
How can i do it?
Thanks in advance
If you want to put the Freespace of E in a variable you can do this :
$VarSpace = $(Get-WmiObject -Class win32_logicaldisk | Where-Object -Property Name -eq C:).FreeSpace/1GB
then you can do a simple if for check :
if ($VarSpace -le 10){ <Something for stopping you script like exit> }
You can use the Get-Volume cmdlet for that or Get-CimInstancerather than the old Get-WmiObject:
$freeOnE = (Get-CimInstance -ClassName win32_logicaldisk | Where-Object {$_.DeviceID -eq 'E:'}).FreeSpace / 1GB
or
$freeOnE = (Get-Volume -DriveLetter E).SizeRemaining / 1GB
Then exit your PowerShell session if this value is below 10Gb
if ($freeOnE -lt 10) { exit }
I'm trying to create a powershell script (getting more advanced... JK. Powershell offers more features than the batch file, and I want to use some of them.)
So, here's my batch script:
:Start
#echo off
set /p password="Password:"
:Nextcomp
set /p computer="Computer name:"
wmic /user:username /password:%password% /node:"%computer%" memorychip get capacity
set /P c=Do you want to get info about another computer (y/n)?
if /I "%c%" EQU "y" goto :Nextcomp
if /I "%c%" EQU "n" goto :End goto :choice
pause
:End
And here's what I found: Script
I modified it for my needs, but whenever I try to run this script, I get it the wrong way - it's displaying me the entire script, and only in the end is it asking me about the computer name:
$resultstxt = "C:\Users\user\Documents\results.csv"
Param(
[Parameter(Mandatory=$true, Position=0, HelpMessage="Password?")]
[SecureString]$password
)
$pw = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
$Computer = Read-Host -Prompt 'Computer name'
$out = #()
If (!(Test-Connection -ComputerName $Computer -Count 1 -Quiet)) {
Write-Host "$Computer not on network."
Continue
}
foreach($object in $HostList) {
$RAM = get-wmiobject -user user -password $pw -computername $object.("Computer")-class win32_physicalmemory
$DeviceInfo= #{}
$DeviceInfo.add("RAM", "$([math]::floor($RAM.Capacity/ (1024 * 1024 * 1024 )) )" + " GB" )
$DeviceInfo.add("Computer Name", $vol.SystemName)
$out += New-Object PSObject -Property $DeviceInfo | Select-Object "RAM"
Write-Verbose ($out | Out-String) -Verbose
$out | Export-CSV -FilePath $resultstxt -NoTypeInformation
}
As you might have guessed, I have a lot more fields, but they all are similar, and I borrowed from a lot of sources, but mainly from the "Script" link.
What I want is:
Hide the password
Export the information to CSV, with each new computer (see 3.) added following the current computer (on the next line)
Ask if I want to get the info about another computer, with "y" key for yes, "n" for no.
Make the script work
I found about the problem 1, but I haven't tested it yet, so... will it work? Next, I found about problem 2, but it would display all info in a not-easy-to-read format, and not everything I need, and all in one cell. Finally, about 3, I found, but it wouldn't work. I can't say I dug the entire Internet, but I'm hoping you guys (and gals?) can help me figure it out. It shouldn't be that hard to resolve these 3 issues, it's not a super complicated script after all, right? My current script is only 31 lines, including the whitespaces.
this is a demo of one way to get basic system info from a group of systems. it uses the CIM cmdlets since they are faster than the WMI cmdlets [most of the time], present datetime info as standard datetime objects, AND not somewhat deprecated.
it also uses the Invoke-Command cmdlet for remote parallelism, and is set to ignore errors so that non-responding systems don't waste your time.
#requires -RunAsAdministrator
# fake reading in a list of computer names
# in real life, use Get-Content or (Get-ADComputer).Name
$ComputerList = #'
Localhost
BetterNotBeThere
127.0.0.1
10.0.0.1
::1
'# -split [environment]::NewLine
$IC_ScriptBlock = {
$CIM_ComputerSystem = Get-CimInstance -ClassName CIM_ComputerSystem
$CIM_BIOSElement = Get-CimInstance -ClassName CIM_BIOSElement
$CIM_OperatingSystem = Get-CimInstance -ClassName CIM_OperatingSystem
$CIM_Processor = Get-CimInstance -ClassName CIM_Processor
$CIM_LogicalDisk = Get-CimInstance -ClassName CIM_LogicalDisk |
Where-Object {$_.Name -eq $CIM_OperatingSystem.SystemDrive}
[PSCustomObject]#{
LocalComputerName = $env:COMPUTERNAME
Manufacturer = $CIM_ComputerSystem.Manufacturer
Model = $CIM_ComputerSystem.Model
SerialNumber = $CIM_BIOSElement.SerialNumber
CPU = $CIM_Processor.Name
SysDrive_Capacity_GB = '{0:N2}' -f ($CIM_LogicalDisk.Size / 1GB)
SysDrive_FreeSpace_GB ='{0:N2}' -f ($CIM_LogicalDisk.FreeSpace / 1GB)
SysDrive_FreeSpace_Pct = '{0:N0}' -f ($CIM_LogicalDisk.FreeSpace / $CIM_LogicalDisk.Size * 100)
RAM_GB = '{0:N2}' -f ($CIM_ComputerSystem.TotalPhysicalMemory / 1GB)
OperatingSystem_Name = $CIM_OperatingSystem.Caption
OperatingSystem_Version = $CIM_OperatingSystem.Version
OperatingSystem_BuildNumber = $CIM_OperatingSystem.BuildNumber
OperatingSystem_ServicePack = $CIM_OperatingSystem.ServicePackMajorVersion
CurrentUser = $CIM_ComputerSystem.UserName
LastBootUpTime = $CIM_OperatingSystem.LastBootUpTime
}
}
$IC_Params = #{
ComputerName = $ComputerList
ScriptBlock = $IC_ScriptBlock
ErrorAction = 'SilentlyContinue'
}
$RespondingSystems = Invoke-Command #IC_Params
$NOT_RespondingSystems = $ComputerList.Where({
# these two variants are needed to deal with an ipv6 localhost address
"[$_]" -notin $RespondingSystems.PSComputerName -and
$_ -notin $RespondingSystems.PSComputerName
})
# if you want to remove the PSShowComputerName, PSComputerName & RunspaceID props, use ...
# Select-Object -Property * -ExcludeProperty PSShowComputerName, PSComputerName, RunspaceId
'=' * 40
$RespondingSystems
'=' * 40
$NOT_RespondingSystems
truncated output ...
LocalComputerName : [MySysName]
Manufacturer : System manufacturer
Model : System Product Name
SerialNumber : System Serial Number
CPU : AMD Phenom(tm) II X4 945 Processor
SysDrive_Capacity_GB : 931.41
SysDrive_FreeSpace_GB : 745.69
SysDrive_FreeSpace_Pct : 80
RAM_GB : 8.00
OperatingSystem_Name : Microsoft Windows 7 Professional
OperatingSystem_Version : 6.1.7601
OperatingSystem_BuildNumber : 7601
OperatingSystem_ServicePack : 1
CurrentUser : [MySysName]\[MyUserName]
LastBootUpTime : 2019-01-24 1:49:31 PM
PSComputerName : [::1]
RunspaceId : c1b949ef-93af-478a-b2cf-e44d874c5724
========================================
BetterNotBeThere
10.0.0.1
to get a well structured CSV file, send the $RespondingSystems collection to the file via Export-CSV.
for a demo of a loop to wrap around any given block of code, take a look at this ...
$Choice = ''
while ([string]::IsNullOrEmpty($Choice))
{
$Choice = Read-Host 'Please enter a valid computer name or [x] to exit '
# replace below with real code to check if $ComputerName is valid
if ($Choice -eq $env:COMPUTERNAME)
{
$ValidCN = $True
}
else
{
$ValidCN = $False
}
if (-not $ValidCN -and $Choice -ne 'x')
{
# insert desired error notice
[console]::Beep(1000, 300)
Write-Warning ''
Write-Warning ('Your choice [ {0} ] is not a valid computer name.' -f $Choice)
Write-Warning ' Please try again ...'
pause
$Choice = ''
}
elseif ($Choice -ne 'x')
{
# insert code to do the "ThingToBeDone"
Write-Host ''
Write-Host ('Doing the _!_ThingToBeDone_!_ to system [ {0} ] ...' -f $Choice)
pause
$Choice = ''
}
}
on screen output ...
Please enter a valid computer name or [x] to exit : e
WARNING:
WARNING: Your choice [ e ] is not a valid computer name.
WARNING: Please try again ...
Press Enter to continue...:
Please enter a valid computer name or [x] to exit : [MySysName]
Doing the _!_ThingToBeDone_!_ to system [ [MySysName] ] ...
Press Enter to continue...:
Please enter a valid computer name or [x] to exit : x
I need to gather volume capacity sizes for all fixed drives on a server. I am limited to using PowerShell 2 because that is what the sysadmins have deployed on the servers. I can get the information on the formatted drives very easily, using the Get-WmiObject Win32_Volume function.
$ComputerName = "."
Get-WmiObject -ComputerName "$computername" Win32_Volume -Filter "DriveType=3" | foreach {
New-Object PSObject -Property #{
SystemName = $_.SystemName
UsageDate = $((Get-Date).ToString("yyyy-MM-dd HH:mm:ss"))
Label = $_.Label
VolumeName = $_.Name
FileSystem = if ($_.FileSystem -eq $null) {"RAW"} else {$_.FileSystem}
Size = if ($_.FileSystem -eq $null) {
Show-Capacity
} else {
$([Math]::Round(($_.Capacity/1GB), 2))
}
Free = if ($_.FileSystem -eq $null) {
"0.00"
} else {
$([Math]::Round(($_.FreeSpace/1GB), 2))
}
PercentFree = if ($_.Capacity -gt 0) {
$([Math]::Round((([float]$_.FreeSpace/[float]$_.Capacity) * 100), 2))
} else {
'0.00'
}
}
}
The Show-Capacity function is as follows:
function Show-Capacity {
$drive=$_.Name
$dpscript = #"
Select Volume '$drive'
Detail Volume
"#
$Temp= #()
[array]$Temp += ,$dpscript | diskpart
foreach ($line in $Temp) {
if ($line.StartsWith("Volume Capacity") ) {
$Values = $line.Split(":")
}
}
$Capacity = $Values.Trim("G", "T", "M", "B", " ")
$Capacity[1]
}
The formatted drives show up correctly as follows:
UsageDate : 2017-11-09 08:08:17
SystemName : MyServerName
Label :
VolumeName : C:\
Size : 99.9
Free : 77.04
PercentFree : 77.11
The Raw Drives show up as follows:
UsageDate : 2017-11-09 08:08:15
SystemName : MyServerName
Label :
VolumeName : I:\
Size :
Free : 0.00
PercentFree : 0.00
I want Raw Drives to show up this way:
UsageDate : 2017-11-09 08:08:15
SystemName : MyServerName
Label :
VolumeName : I:\
Size : 12000.0
Free : 0.00
PercentFree : 0.00
In the PowerShell logs I see the error: "Cannot index into a null array. At {path}:12 char 11. I'm also getting a trim error, but that is of lesser concern. I've been working on this and reading lots of posts for about 2 weeks now and have not been successful.
I tried the method outlined in this line of posts:
https://blogs.technet.microsoft.com/heyscriptingguy/2013/08/30/automating-diskpart-with-windows-powershell-part-5/
This will always be run on local computer, but will be exported to CSV and aggregated.
I have written few powershell command to perform some auditing on HyperV Clusters. The command works fine, But can anyone help me to trim the output, so that I can collect what I need ?
##Audit-CreatingDC
$AuditDC = Invoke-Command -ComputerName $ComputerName {Get-ChildItem -Path HKLM:\cluster\resources -recurse | get-itemproperty -name CreatingDC -erroraction 'silentlycontinue'}| ft CreatingDC,PSComputerName
####Audit-iSCSI
#Show which hosts are not communicating to the storage with the ‘-s’ and where there are duplicated targets:
$AuditISCSI = Invoke-Command -ComputerName $ComputerName { get-iscsisession } | FT PSComputerName, InitiatorPortalAddress, IsConnected -autosize
######Discover checkdsk errors - "Scan Needed". Execute using txt of one node from each cluster.
$AuditCHKDSK = Invoke-Command -ComputerName $ComputerName { get-volume | Where-Object –FilterScript { $_.HealthStatus -eq "Scan Needed" }} | FT PSComputerName, FileSystem, HealthStatus -autosize
And the output for each is below
CreatingDC PSComputerName
---------- --------------
\\dc-sc-02.oim.corp.com slcoc037
PSComputerName InitiatorPortalAddress IsConnected
-------------- ---------------------- -----------
slcoc037 10.214.61.107 True
PSComputerName FileSystem HealthStatus
-------------- ---------- ------------
slcoc037 CSVFS 1
But I need the output for above in this format
\\dc-sc-02.oim.corp.com
10.241.81.107
CSVFS 1
Can anyone help me to trim these 3 commands ?
You probably already know that almost all powershell outputs are objects. Objects have properties. Displaying a particular property would use the syntax $Object.Propertyname. In your case, CreatingDC is a property of the $AuditDC Variable object. Applying that logic, all you need to do is, display it like this:
$AuditDC.CreatingDC
$AuditISCSI.InitiatorPortalAddress
$AuditCHKDSK.FileSystem