Use Alternate Credentials for PowerShell ADSI Provider WinNT Query

前端 未结 2 1999
难免孤独
难免孤独 2021-01-26 19:06

What am I trying to do?

Hi! I am writing a script that can accept 2 parameters, ComputerName and CheckWhatFile. The script will then access the computer

相关标签:
2条回答
  • 2021-01-26 19:44

    As it stands, the only way you're going to be able to do that is to have them RDP to the file server using the Admin credentials and run the script there. That's the only way they're going to get a powershell console to be able to see that output. Without powershell remoting enabled you can only get a local session, and that means either a local logon or RDP.

    0 讨论(0)
  • 2021-01-26 20:03

    Something like this might work:

    $provider = "WinNT://$ComputerName/LanmanServer"
    $cred     = Get-Credential
    
    $netfile  = New-Object DirectoryServices.DirectoryEntry(
                  $provider, $cred.UserName, $cred.GetNetworkCredential().Password
                )
    $netfile.Invoke("Resources") | % {
      ...
    }
    
    0 讨论(0)
提交回复
热议问题