samersultan / wsus-cleanup

PowerShell Script for cleaning up WSUS
41 stars 20 forks source link

[Error] Script fails to run when called from Admin prompt #6

Open alta01 opened 4 years ago

alta01 commented 4 years ago

Issue: When running script from designated share as an administrator, the script fails to run.

Expected behavior: Script makes connection to local WSUS database for cleanup.

Error Log:

PS E:\wsus-cleanup-master> E:\wsus-cleanup-master\WSUS-Cleanup.ps1 Cannot invoke method. Method invocation is supported only on core types in this language mode. At E:\wsus-cleanup-master\WSUS-Cleanup.ps1:12 char:67

  • ... indowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
  • 
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage

New-Object : Cannot create type. Only core types are supported in this language mode. At E:\wsus-cleanup-master\WSUS-Cleanup.ps1:12 char:18

  • ... rrentUser = New-Object Security.Principal.WindowsPrincipal $([Securit ...
  • 
    + CategoryInfo          : PermissionDenied: (:) [New-Object], PSNotSupportedException
    + FullyQualifiedErrorId : CannotCreateTypeConstrainedLanguage,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression. At E:\wsus-cleanup-master\WSUS-Cleanup.ps1:13 char:3

  • $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Admi ...
  • 
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

running with full privileges Cannot invoke method. Method invocation is supported only on core types in this language mode. At E:\wsus-cleanup-master\WSUS-Cleanup.ps1:74 char:10

  • if ( -not [System.Diagnostics.EventLog]::SourceExists($log_source ...
  • 
    + CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage

Environment: Windows Server 2016 Datacenter Edition Additional Comments: No items added to config file. Script running on server where WSUS is hosted so $SqlServer and $SqlDB variables are empty