Hi,
I am able to get the folder details, if I pass the folder details as below.
Get-Folder = "Dept-01", "Dept-02", "Dept-03"
But If I assign the same to variable, it is not working and getting the below error. please help!!
$str = '"Dept-01", "Dept-02", "Dept-03"'
$modifiedString = $str -replace '"', ''
get-folder $modifiedString
Error
get-folder : 8/11/2023 5:11:41 AM Get-Folder Folder with name 'Dept-01, Dept-02, Dept-03' was not found using the specified filter(s).
At line:1 char:1
+ get-folder $modifiedString
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Folder], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder
The get rid of te double quotes.
$modifiedString = ($str.Replace(' ','').Replace('"','')) -split ','
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try with
$modifiedString = ($str.Replace(' ','')) -split ','
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Split is working as expected.
PS D:\myreports> $str = '"Dept-01","Dept-02","Dept-03"'
PS D:\myreports> $modifiedString = ($str.Replace(' ','')) -split ','
PS D:\myreports> $modifiedString
"Dept-01"
"Dept-02"
"Dept-03"
but when I use the variable for get-folder, i am getting error.
PS D:\myreports>
PS D:\myreports> get-folder $modifiedString
get-folder : 8/11/2023 6:55:06 AM Get-Folder Folder with name '"Dept-01"' was not found using the specified filter(s).
At line:1 char:1
+ get-folder $modifiedString
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Folder], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder
get-folder : 8/11/2023 6:55:06 AM Get-Folder Folder with name '"Dept-02"' was not found using the specified filter(s).
At line:1 char:1
+ get-folder $modifiedString
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Folder], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder
get-folder : 8/11/2023 6:55:06 AM Get-Folder Folder with name '"Dept-03"' was not found using the specified filter(s).
At line:1 char:1
+ get-folder $modifiedString
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Folder], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetFolder
Here I am trying to get total CPU count from all three department folders.
(Get-Folder $modifiedString | Get-VM | Measure-Object -Property numcpu -Sum).Sum
The get rid of te double quotes.
$modifiedString = ($str.Replace(' ','').Replace('"','')) -split ','
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect. Thank you very much LucD, it worked now.