0
嘗試使用Get-WmiObject獲取遠程PC上當前或最近一次登錄的用戶名,然後將該值存儲到變量中,以便日後使用它作爲路徑的一部分。Powershell - 在遠程主機上登錄用戶並將用戶名作爲變量登錄
我嘗試這個,但我的變量只是空白。有任何想法嗎?提前致謝。
$gottenUserName = (Get-WmiObject -ComputerName $thaTargetHost -Namespace root\cimv2 -Class Win32_ComputerSystem)[0].UserName;
我還沒有得到任何價值 – superKing
當你剛剛查詢的Win32_ComputerSystem找回一個值,是有顯示用戶名屬性了什麼? 'Get-WmiObject -ComputerName $ thaTargetHost -Class Win32_ComputerSystem |選擇用戶名' – boeprox
Win32_ComputerSystem沒有用戶名屬性 –