Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run few PS1 scripts #1

Open
Anupthegeek opened this issue Apr 28, 2021 · 1 comment
Open

Unable to run few PS1 scripts #1

Anupthegeek opened this issue Apr 28, 2021 · 1 comment

Comments

@Anupthegeek
Copy link

Hi,

I am unable to run below scripts, I get the exceptions as stated:

1. vmUsers.ps1

Cannot index into a null array.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsers.ps1:27 char:3

  •     $line = $content[$i]
    
  •     ~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray

You cannot call a method on a null-valued expression.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsers.ps1:28 char:3

  •     $dateLine = $line.Split(",")[0]
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

Get-Date : Cannot bind parameter 'Date' to the target. Exception setting "Date": "Cannot convert null to type
"System.DateTime"."
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsers.ps1:30 char:17

  •     if ((Get-Date $dateLine) -gt (Get-Date $date)) {
    
  •                   ~~~~~~~~~
    
    • CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
    • FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

Cannot index into a null array.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsers.ps1:27 char:3

  •     $line = $content[$i]
    
  •     ~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArray

You cannot call a method on a null-valued expression.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsers.ps1:28 char:3

  •     $dateLine = $line.Split(",")[0]
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

Get-Date : Cannot bind parameter 'Date' to the target. Exception setting "Date": "Cannot convert null to type
"System.DateTime"."
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsers.ps1:30 char:17

  •     if ((Get-Date $dateLine) -gt (Get-Date $date)) {
    
  •                   ~~~~~~~~~
    
    • CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
    • FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

    2. vmUsage.ps1

Get-DesktopVM : No output object matching the Pool_id parameter
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsage.ps1:13 char:10

  • $vms += Get-DesktopVM -Pool_id $pool.pool_id
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (vmware.view.pow...ts.GetDesktopVM:GetDesktopVM) [Get-DesktopVM], Ex
      ion
    • FullyQualifiedErrorId : No object,vmware.view.powershell.cmdlets.GetDesktopVM

Method invocation failed because [vmware.view.powershell.cmdlets.DesktopVM] does not contain a method named
'op_Addition'.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsage.ps1:13 char:2

  • $vms += Get-DesktopVM -Pool_id $pool.pool_id
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
    • FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [vmware.view.powershell.cmdlets.DesktopVM] does not contain a method named
'op_Addition'.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsage.ps1:13 char:2

  • $vms += Get-DesktopVM -Pool_id $pool.pool_id
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
    • FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [vmware.view.powershell.cmdlets.RemoteSession] does not contain a method named
'op_Addition'.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\vmUsage.ps1:12 char:2

  • $sessions += Get-RemoteSession -Pool_id $pool.pool_id -ErrorActio ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
    • FullyQualifiedErrorId : MethodNotFound

    3. unusedVMs.ps1

    & : File \vmmanager\E\Project\data\scripts\lastLogin.ps1 cannot be loaded. The file
    \vmmanager\E\Project\data\scripts\lastLogin.ps1 is not digitally signed. You cannot run this script on the current
    system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
    http://go.microsoft.com/fwlink/?LinkID=135170.
    At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\unusedVMs.ps1:11 char:12

  • $list = & $folder"scripts\lastLogin.ps1" $date
    
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : SecurityError: (:) [], PSSecurityException
    • FullyQualifiedErrorId : UnauthorizedAccess
      & : File \vmmanager\E\Project\data\scripts\lastLogin.ps1 cannot be loaded. The file
      \vmmanager\E\Project\data\scripts\lastLogin.ps1 is not digitally signed. You cannot run this script on the current
      system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
      http://go.microsoft.com/fwlink/?LinkID=135170.
      At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\unusedVMs.ps1:11 char:12
  • $list = & $folder"scripts\lastLogin.ps1" $date
    
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : SecurityError: (:) [], PSSecurityException
    • FullyQualifiedErrorId : UnauthorizedAccess
      & : File \vmmanager\E\Project\data\scripts\lastLogin.ps1 cannot be loaded. The file
      \vmmanager\E\Project\data\scripts\lastLogin.ps1 is not digitally signed. You cannot run this script on the current
      system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
      http://go.microsoft.com/fwlink/?LinkID=135170.
      At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\unusedVMs.ps1:11 char:12
  • $list = & $folder"scripts\lastLogin.ps1" $date
    
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : SecurityError: (:) [], PSSecurityException
    • FullyQualifiedErrorId : UnauthorizedAccess
      & : File \vmmanager\E\Project\data\scripts\lastLogin.ps1 cannot be loaded. The file
      \vmmanager\E\Project\data\scripts\lastLogin.ps1 is not digitally signed. You cannot run this script on the current
      system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
      http://go.microsoft.com/fwlink/?LinkID=135170.
      At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\unusedVMs.ps1:11 char:12
  • $list = & $folder"scripts\lastLogin.ps1" $date
    
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : SecurityError: (:) [], PSSecurityException
    • FullyQualifiedErrorId : UnauthorizedAccess
      & : File \vmmanager\E\Project\data\scripts\lastLogin.ps1 cannot be loaded. The file
      \vmmanager\E\Project\data\scripts\lastLogin.ps1 is not digitally signed. You cannot run this script on the current
      system. For more information about running scripts and setting execution policy, see about_Execution_Policies at
      http://go.microsoft.com/fwlink/?LinkID=135170.
      At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\unusedVMs.ps1:11 char:12
  • $list = & $folder"scripts\lastLogin.ps1" $date
    
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : SecurityError: (:) [], PSSecurityException
    • FullyQualifiedErrorId : UnauthorizedAccess

    4. lastLogin.ps1

Get-Content : A positional parameter cannot be found that accepts argument 'Select-String'.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\lastLogin.ps1:23 char:17

  • ... teAndUser = Get-Content "$usageFileLocation$file" Select-String -NotM ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Get-Content], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Get-Content : A positional parameter cannot be found that accepts argument 'Select-String'.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\lastLogin.ps1:23 char:17

  • ... teAndUser = Get-Content "$usageFileLocation$file" Select-String -NotM ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Get-Content], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Get-Content : A positional parameter cannot be found that accepts argument 'Select-String'.
At C:\Users\anupcp\Desktop\vmware-vdi-master\scripts\lastLogin.ps1:23 char:17

  • ... teAndUser = Get-Content "$usageFileLocation$file" Select-String -NotM ...

  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Get-Content], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand

    Any help would be much appreicated.

    Thanks

@SethosII
Copy link
Owner

SethosII commented May 4, 2021

@Anupthegeek:

  1. The script can't find data that needs to be generated in advance by vmUsage.ps1, therefore the variables are empty and you see these errors.
  2. I think you are missing the VMware Horizon Powershell modules because of the ObjectNotFound error or the expression on the right needs to be placed in parentheses.
  3. This seems to be running on a different computer. Your powershell execution policy on this one does not allow to run the script.
  4. The pipes are missing in the file, so something went wrong while copying the script or so. The line should look like this: https://github.com/SethosII/vmware-vdi/blob/master/scripts/lastLogin.ps1#L23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants