Use Alternate Credentials for PowerShell ADSI Provider WinNT Query

前端 未结 2 2000
难免孤独
难免孤独 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 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") | % {
      ...
    }
    

提交回复
热议问题