Powershell for SharePoint >> getting we!rd error - powershell

I keep getting following error on this code:
#Setup default variables
$webUrl = Get-SPWeb -Identity "http://CiscoIntranet/sites/VOIP"
$list = $webUrl.GetList("http://CiscoIntranet/sites/VOIP/ForwardTech")
[System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”)
function ProcessMove {
param($folderUrl)
$folder = $web.GetFolder($folderUrl)
foreach ($file in $folder.Files)
{
[Microsoft.SharePoint.SPFile]$spFile = $file;
$docset=$($file.Counterparty2);
$destinationFolderUrl = "http://CiscoIntranet/sites/VOIP/ForwardTech/" + $docset;
$spFile.MoveTo($destinationFolderUrl + $file.Name, $true);
$webUrl.Update();
}
}
#Move root Files
ProcessMove($list.RootFolder.Url)
You cannot call a method on a null-valued expression.
At C:\PS\MoveFiles.ps1:8 char:28
+ $folder = $web.GetFolder <<<< ($folderUrl)
+ CategoryInfo : InvalidOperation: (GetFolder:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Method invocation failed because [Microsoft.SharePoint.SPListItemCollection] doesn't contain a method named 'MoveTo'.
At C:\PS\MoveFiles.ps1:13 char:23
+ $list.Items.MoveTo <<<< ($destinationFolderUrl + $file.Name, $true);
+ CategoryInfo : InvalidOperation: (MoveTo:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

This is the working code...
$siteURL="http://CiscoIntranet/sites/VOIP"
$docLib = "ForwardTech"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$collFiles=$web.GetFolder($docLib).Files
$count=$collFiles.Count
while($count -ne 0)
{
$item = $collFiles[$count-1].Item
$DocSet = $item["Region"]
Write-Host "$DocSet is the doc set. $collFiles[$count-1].Name is name"
$collFiles[$count-1].MoveTo($siteURL + "/" + $docLib + "/" + $DocSet + "/" + $collFiles[$count-1].Name, $true)
$count--
}

Related

Adding empty line in powershell script creates errors

I have just encountered a very weird error: whenever I just add an empty line in a ps1 file which is otherwise working really fine, my script generates errors.
Here is the setup:
Because I had dependencies issues, I now have an Includes.ps1 file with that content:
$ScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. ("$ScriptDirectory\HelperFunctions.ps1")
. ("$ScriptDirectory\BuildParameters.ps1")
. ("$ScriptDirectory\Platform.ps1")
. ("$ScriptDirectory\Configuration.ps1")
. ("$ScriptDirectory\Action.ps1")
. ("$ScriptDirectory\Backup.ps1")
I have a Package.ps1 file which includes that file, and does the stuff of instanciating the needed classes and make them work together:
$ScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. ("$ScriptDirectory\Includes.ps1")
Clear-Host
$Parameters = New-Object -TypeName "BuildParameters"
$user_variables_path = "./UserVariables.ps1"
if ( Test-Path $user_variables_path )
{
. $user_variables_path
}
$Parameters.ValidateParameters()
$PlatformClass = $PlatformFactory.MakePlatform( $Parameters.Platform )
$PlatformClass.ValidateParameters( $Parameters )
$ConfigurationClass = $ConfigurationFactory.MakeConfiguration( $Parameters.Configuration )
$ConfigurationClass.ValidateParameters( $Parameters )
$ActionClass = $ActionsFactory.MakeAction( $Parameters.Action, $PlatformClass, $ConfigurationClass, $Parameters )
$ActionClass.ValidateParameters()
$Backup = [ Backup ]::new( $Parameters, $PlatformClass )
$Backup.ValidateParameters();
$ActionClass.Execute()
if ( $Parameters.BackupVersion )
{
$Backup.BackupVersion()
}
Here is the Platforms.ps1 file which gives me errors when I edit it:
class Platform
{
[Boolean] $CanBePatched
[Boolean] $CanCompressData
Platform()
{
$this.CanBePatched = $false
$this.CanCompressData = $true
}
[void] ValidateParameters( [BuildParameters] $Parameters )
{
}
}
class PlatformWin64 : Platform
{
PlatformWin64()
{
}
}
class PlatformXboxOne : Platform
{
PlatformXboxOne()
{
}
}
class PlatformSwitch : Platform
{
PlatformSwitch()
{
$this.CanBePatched = $true
}
[void] ValidateParameters( [BuildParameters] $Parameters )
{
if ( [string]::IsNullOrEmpty( $Parameters.Region ) )
{
WriteErrorAndExit( "You need to specify a region for the PS4" )
}
}
}
class PlatformPS4 : Platform
{
PlatformPS4()
{
$this.CanBePatched = $true
$this.CanCompressData = $false
}
[void] ValidateParameters( [BuildParameters] $Parameters )
{
if ( [string]::IsNullOrEmpty( $Parameters.Region ) )
{
WriteErrorAndExit( "You need to specify a region for the PS4" )
}
}
}
class PlatformFactory
{
[Platform] MakePlatform( [String] $name )
{
return (New-Object -TypeName "Platform$name")
}
}
$PlatformFactory = [PlatformFactory]::new()
When I change the contents of that file, even by adding empty lines, running the script gives me those errors:
Cannot convert argument "Platform", with value: "PlatformWin64", for
"MakeAction" to type "Platform": "Cannot convert the "PlatformWin64" value
of type "PlatformWin64" to type "Platform"."
At F:\Projects\RWC\BuildScripts\Utils\Package.ps1:55 char:1
+ $ActionClass = $ActionsFactory.MakeAction( $Parameters.Action, $Platf ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
You cannot call a method on a null-valued expression.
At F:\Projects\RWC\BuildScripts\Utils\Package.ps1:56 char:1
+ $ActionClass.ValidateParameters()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Cannot convert argument "Platform", with value: "PlatformWin64", for
".ctor" to type "Platform": "Cannot convert the "PlatformWin64" value of
type "PlatformWin64" to type "Platform"."
At F:\Projects\RWC\BuildScripts\Utils\Package.ps1:58 char:1
+ $Backup = [ Backup ]::new( $Parameters, $PlatformClass )
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
You cannot call a method on a null-valued expression.
At F:\Projects\RWC\BuildScripts\Utils\Package.ps1:59 char:1
+ $Backup.ValidateParameters();
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At F:\Projects\RWC\BuildScripts\Utils\Package.ps1:61 char:1
+ $ActionClass.Execute()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At F:\Projects\RWC\BuildScripts\Utils\Package.ps1:65 char:5
+ $Backup.BackupVersion()
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Well it turns out I had to close the powershell command line and run it again to have my modifications not generate any errors.
That post helped me find the cause...

Recursively Changing File extensions from .docx and .pdf to .txt

$findPDF = Get-ChildItem -Path "$fileDrive" -Filter *.pdf -r
$findDOCX = Get-ChildItem -Path "$fileDrive" -Filter *.docx -r
$pullFiles += $findPDF
$pullFiles += $findDOCX
#[array]$pullFiles
#$pullFiles.length
$holdPath = #()
for($i = 0; $i -lt $pullFiles.length; $i++){
#get the full path of each document
$fullPath = Resolve-Path $pullFiles.fullname[$i]
#stores the information in a global array
$holdPath += $fullPath.path
}
#$holdPath
<#
.DESCRIPTION Uses the word.APPLICATION object to open and convert the word documents into .txt.
#>
#https://stackoverflow.com/questions/13402898/how-can-i-use-powershell-to-save-as-a-different-file-extension
#wdFormatDOSTextLineBreaks 5 Microsoft DOS text with line breaks preserved.
foreach($fi in $holdPath){
$Doc = $word.Documents.Open($fi.name)
$NameDOCX = ($Doc.name).replace("docx","txt")
$Doc.saveas([ref] $NameDOCX, [ref] 5)
$NamePDF = ($Doc.name).replace("pdf","txt")
$Doc.saveas([ref] $NamePDF, [ref] 5)
$Doc.close()
}
The problem Statement
The program needs to get any pdf and doc/x file and convert it to a .txt file. Now, I am able to recursively search and pull all .docx and .pdf documents from the file system. Now, I just need to convert them.
The Error
You cannot call a method on a null-valued expression.
At C:\Users\p617824\Documents\files\powershell\fileExtRename.ps1:38 char:2
+ $Doc = $word.Documents.Open($fi.name)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\p617824\Documents\files\powershell\fileExtRename.ps1:40 char:2
+ $NameDOCX = ($Doc.name).replace("docx","txt")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
[ref] cannot be applied to a variable that does not exist.
At C:\Users\p617824\Documents\files\powershell\fileExtRename.ps1:41 char:2
+ $Doc.saveas([ref] $NameDOCX, [ref] 5)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (NameDOCX:VariablePath) [], RuntimeException
+ FullyQualifiedErrorId : NonExistingVariableReference
You cannot call a method on a null-valued expression.
At C:\Users\p617824\Documents\files\powershell\fileExtRename.ps1:43 char:2
+ $NamePDF = ($Doc.name).replace("pdf","txt")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
[ref] cannot be applied to a variable that does not exist.
At C:\Users\p617824\Documents\files\powershell\fileExtRename.ps1:44 char:2
+ $Doc.saveas([ref] $NamePDF, [ref] 5)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (NamePDF:VariablePath) [], RuntimeException
+ FullyQualifiedErrorId : NonExistingVariableReference
You cannot call a method on a null-valued expression.
At C:\Users\p617824\Documents\files\powershell\fileExtRename.ps1:46 char:2
+ $Doc.close()
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
$word variable are not initialized, and your are complicated for Nothing (without offense you). Modify all your script like this :
$fileDrive ="C:\temp"
$word = new-object -ComObject Word.Application
Get-ChildItem -Path $fileDrive -file -r -Include "*.docx", "*.pdf" | %{
$Doc = $word.Documents.Open($_.FullName)
$NameDOC = $_.FullName.replace(".docx",".txt").replace(".pdf",".txt")
$Doc.saveas([ref] $NameDOC, [ref] 5)
$Doc.close()
}
$word.Quit()
But i have doubt on convert pdf to .txt with Word application like this... I think you should use itextsharp libray like here

Powershell won't read header text in word documents?

I am in need of checkingh a larger number of word documents (doc & docx) for a specific text and found a great tutorial and script by the Scripting Guys;
https://blogs.technet.microsoft.com/heyscriptingguy/2012/08/01/find-all-word-documents-that-contain-a-specific-phrase/
The script reads all documents in a directory and gives the following output;
Number of times mentioned
Total word count in all documents where the specific text is found
The directory of all files containing the specific text.
This is all I need, however their code doesn't seem to actually check the headers of any document, which incidentally is where the specific text I'm looking for is located. Any tips & tricks in making the script read header text would make me very happy.
An alternative solution might be to remove the formatting so that the header text becomes part of the rest of the document? Is this possible?
Edit: Forgot to link the script:
[cmdletBinding()]
Param(
$Path = "C:\Users\use\Desktop\"
) #end param
$matchCase = $false
$matchWholeWord = $true
$matchWildCards = $false
$matchSoundsLike = $false
$matchAllWordForms = $false
$forward = $true
$wrap = 1
$application = New-Object -comobject word.application
$application.visible = $False
$docs = Get-childitem -path $Path -Recurse -Include *.docx
$findText = "specific text"
$i = 1
$totalwords = 0
$totaldocs = 0
Foreach ($doc in $docs)
{
Write-Progress -Activity "Processing files" -status "Processing $($doc.FullName)" -PercentComplete ($i /$docs.Count * 100)
$document = $application.documents.open($doc.FullName)
$range = $document.content
$null = $range.movestart()
$wordFound = $range.find.execute($findText,$matchCase,
$matchWholeWord,$matchWildCards,$matchSoundsLike,
$matchAllWordForms,$forward,$wrap)
if($wordFound)
{
$doc.fullname
$document.Words.count
$totaldocs ++
$totalwords += $document.Words.count
} #end if $wordFound
$document.close()
$i++
} #end foreach $doc
$application.quit()
"There are $totaldocs and $($totalwords.tostring('N')) words"
#clean up stuff
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($range) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($document) | Out-Null
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($application) | Out-Null
Remove-Variable -Name application
[gc]::collect()
[gc]::WaitForPendingFinalizers()
EDIT 2: My colleague got the idea to call on the section header instead;
Foreach ($doc in $docs)
{
Write-Progress -Activity "Processing files" -status "Processing $($doc.FullName)" -PercentComplete ($i /$docs.Count * 100)
$document = $application.documents.open($doc.FullName)
# Load first section of the document
$section = $doc.sections.item(1);
# Load header
$header = $section.headers.Item(1);
# Set the range to be searched to only Header
$range = $header.content
$null = $range.movestart()
$wordFound = $range.find.execute($findText,$matchCase,
$matchWholeWord,$matchWildCards,$matchSoundsLike,
$matchAllWordForms,$forward,$wrap,$Format)
if($wordFound) [script continues as above]
But this is met with the following errors:
You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\count_mod.ps1:27 char:31
+ $section = $doc.sections.item <<<< (1);
+ CategoryInfo : InvalidOperation: (item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\count_mod.ps1:29 char:33
+ $header = $section.headers.Item <<<< (1);
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\count_mod.ps1:33 char:26
+ $null = $range.movestart <<<< ()
+ CategoryInfo : InvalidOperation: (movestart:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\count_mod.ps1:35 char:34
+ $wordFound = $range.find.execute <<<< ($findText,$matchCase,
+ CategoryInfo : InvalidOperation: (execute:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Is this the right way to go or is it a dead end?
if you want the header text, you can try the following:
$document.content.Sections.First.Headers.Item(1).range.text
For anyone looking at this question in the future: Something isn't quite working with my code above. It seems to return a false positive and puts $wordFound = 1 regardless of the content of the document thus listing all documents found under $path.
Editing the variables within Find.Execute doesn't seem to change the outcome of $wordFound. I believe the problem might be found in my $range, as it is the only place I get errors in while going through the code step by step.
Errors listed;
You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\Powershell\count.ps1:24 char:58
+ $range = $document.content.Structures.First.Headers.Item <<<< (1).range.Text
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "MoveStart" with "0" argument(s): "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"
At C:\Users\user\Desktop\Powershell\count.ps1:25 char:26
+ $null = $range.MoveStart <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodCOMException
You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\Powershell\count.ps1:26 char:34
+ $wordFound = $range.Find.Execute <<<< ($findText,$matchCase,
+ CategoryInfo : InvalidOperation: (Execute:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Adding multiple users to AD

This script was working just fine today while testing. I made a few changes and started getting an error. I then went back to the very original script I got from the internet and now even it does not work. The errors are:
Exception calling "SetInfo" with "0" argument(s): "A constraint violation
occurred."
At C:\Scripts\CreateTest2.ps1:51 char:2
+ $LABUser.SetInfo()
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
Exception calling "Invoke" with "2" argument(s): "There is no such object on the
server."
At C:\Scripts\CreateTest2.ps1:55 char:2
+ $LABUser.psbase.invoke("setPassword", $Pwrd)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation
Exception calling "InvokeSet" with "2" argument(s): "The directory property
cannot be found in the cache"
At C:\Scripts\CreateTest2.ps1:56 char:2
+ $LABUser.psbase.invokeSet("AccountDisabled", $false)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation
Exception calling "CommitChanges" with "0" argument(s): "A constraint violation
occurred."
At C:\Scripts\CreateTest2.ps1:57 char:2
+ $LABUser.psbase.CommitChanges()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Here is the script. What am I doing wrong?
function Select-FileDialog {
param(
[string]$Title,
[string]$Directory,
[string]$Filter = "CSV Files(*.csv)|*.csv"
)
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$objForm = New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory = $Directory
$objForm.Filter = $Filter
$objForm.Title = $Title
$objForm.ShowHelp = $true
$Show = $objForm.ShowDialog()
if ($Show -eq "OK") {
return $objForm.FileName
} else {
exit
}
}
$FileName = Select-FileDialog -Title "Import an CSV file" -Directory "c:\"
$SelectOU = "OU=Test2,OU=Users,OU=Domain Controllers"
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()
$DomainDN = (([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | ? {$_.Name -eq $domain}).GetDirectoryEntry().distinguishedName
$final = "LDAP://$DomainDN"
$DomainPath = [ADSI]"$final"
$UserInformation = Import-Csv $FileName
$OUPath = "LDAP://$SelectOU,$DomainDN"
$UserPath = [ADSI]"$OUPath"
foreach ($User in $UserInformation) {
$CN = $User.samAccountName
$SN = $User.Surname
$Given = $User.givenName
$samAccountName = $User.samAccountName
$Display = $User.DisplayName
$LABUser = $UserPath.Create("User", "CN=$CN")
Write-Host "Please Wait..."
$LABUser.Put("samAccountName", $samAccountName)
$LABUser.Put("sn", $SN)
$LABUser.Put("givenName", $Given)
$LABUser.Put("displayName", $Display)
$LABUser.Put("userPrincipalName", "$samAccountName#$domain")
$LABUser.SetInfo()
$Pwrd = $User.Password
$LABUser.psbase.invoke("setPassword", $Pwrd)
$LABUser.psbase.invokeSet("AccountDisabled", $false)
$LABUser.psbase.CommitChanges()
}
Write-Host "Script Completed"
Can you please try Removing the Quotes from
1) LABUser assignment i.e. CN = $CN.
2) Remove the CN = from that line.
Try it one by one i hope you get your answer.

How to solve an error "you cannot call a method on a null-valued expression"?

While I have written the below code. while Migrating all the servers
Import-Module OperationsManager
$loc= Get-Location
$servers= Get-Content -path $Loc\agentlist.txt
foreach($server in $servers)
{$agent = Get-SCOMAgent -DNSHostName "$server"
$primaryMS = $agent.GetPrimaryManagementServer()
write-host "$server has Current Primary ManagementServer: "$primaryMS.Name
Write-Host "----------------------------------------------------" -ForegroundColor Cyan
}foreach($server in $servers)
{
$agent = Get-SCOMAgent -DNSHostName "$server"
$failoverMSs = $agent.GetFailoverManagementServers()
write-host "Got"$failoverMSs.Count"failover Management Servers for $server"
foreach($failoverMS in $failoverMSs) {
$failoverMS.Name
Write-Host "------------------------------------" -ForegroundColor Cyan
}
}
When I am running the above code I'm getting error as below.
You cannot call a method on a null-valued expression. At
C:\Untitled1.ps1:9 char:1
+ $primaryMS = $agent.GetPrimaryManagementServer()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull DB3CRMS106APW02 has Current Primary ManagementServer:
---------------------------------------------------- You cannot call a method on a null-valued expression. At C:\Untitled1.ps1:19 char:1
+ $failoverMSs = $agent.GetFailoverManagementServers()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull Got 0 failover Management Servers for DB3CRMS106APW02