I was trying to work on something that I felt would not be a timely or overly complex endeavor. Unfortunately I ran into the thrown error “Edit-WKSWorkspaceProperty : Cannot convert ‘System.Object’ to the type ‘System.String’ required by parameter ‘WorkspaceId’. Specified method is not supported.”
While trying to understand the why before getting into possible “how’s” on correcting it, I’ve confused myself more so. I at least feel that the values in the array or how I have assigned said values from the CSV is where my problem lies compared to the parameter’s value type that’s expected.
The full code is as follows:
# Powershell script execution policy specification to allow running of this script
# Latest version of Windows Server shoould be defaulted to this policy already
Set-ExecutionPolicy RemoteSigned
# Importing Cmdlets from the Powershell modules ActiveDirectory & AWSPowershell
Import-Module ActiveDirectory
Import-Module AWSPowershell
Initialize-AWSDefaultConfiguration -ProfileName Company -Region us-west-2
#Array for holding workspace IDs from CSV file
$WorkspaceID = @()
$WorkspaceRegion = "us-west-2"
$WorkspaceProtocol = "WSP"
Import-Csv c:\Temp\WorkspaceIDs.csv | Foreach-object {
Write-Host "Workspace ID to migrate to WSP protocol on us-west-2 is as follows...."
Write-Host "$($_.ID)"`n`n
}
#Import contents and store it in the array named $WorkspaceID
$WorkspaceID = Import-Csv c:\Temp\WorkspaceIDs.csv
#Trying a Foreach() method to process actions over each iteration
#Error being thrown: "Edit-WKSWorkspaceProperty : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'WorkspaceId'. Specified method is not supported."
$WorkspaceID.ForEach({
Edit-WKSWorkspaceProperty -WorkspaceID $WorkspaceID -Region $WorkspaceRegion -WorkspaceProperties_Protocol $WorkspaceProtocol
})
#Not primary objective, but possibly would like to verify each ID's properties after the edit protocol change is successful.
#Will most likely throw the same error "Edit-WKSWorkspaceProperty : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'WorkspaceId'. Specified method is not supported."
#Using comment block, not ready to test segment.
<#foreach ($ID in $WorkspaceID)
{
Get-WKSWorkspace -Region $WorkspaceRegion -WorkspaceId $WorkspaceID | Select-Object -ExpandProperty WorkspaceProperties)
}#>```
Please go back, edit your question and fix the formatting of the code.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
My CSV file is just a single column with a header called ID, then each cell beneath that has values that begin with ws- followed by various letters and a few numbers when the workspace ID is generated in the system. As for the error, would I simply not be able to automate that command or particularly the parameter against a list of IDs one at a time from a array of values?
I even tried starting it as Foreach ($ID in $WorkspaceID) { with the same command inside of the brackets
Both unnecessary … correctly installed modules will be loaded automatically.
A better option would be to use the #requires statement. This would prevent the script from running if the necessary modules were not installed.
Initialize-AWSDefaultConfiguration -ProfileName Company -Region us-west-2
Import-Csv c:\Temp\WorkspaceIDs.csv |
Foreach-object {
Write-Host "Workspace ID to migrate to WSP protocol on us-west-2 is as follows...."
Write-Host "$($_.ID)"`n`n
}
Unnecessary … consider using proper logging if needed instead of Write-Host.
If you insist of outputting unnecessary pixels on the console you should import your CSV file once, save it to a variable and use it as often as needed.