I have this code below which does everything expect create the output file on the server. Now, I can manually create a .txt file on this share
so I do have the needed rights. Also, this snippet works and will create the .txt on the server share.
$LU="TestUser2"
$LU | Out-file"\\Server\logs\$LU.txt"
But the following does not create the .txt on the serve share. (at the bottom I included the output of my program)
$LU= [Environment]::UserName
$LU
$HasRun=Test-Path"\\server\Logs\$LU.txt"
$HasRun
If ($HasRun) {Exit}
net localgroup administrators > c:\temp\$LU.txt
$IsMember=Get-Content c:\temp\$LU.txt
$IsMember
If ($IsMember-contains$LU) {$LU | Out-file"\\server\Logs\$LU.txt"}
## I have tried many different things on this IF statement. -contains, -like, -eq '*$LU*' etc...etc....
##### OUTPUT #####
TestUser2
False
Alias name administrators
Comment Administrators have complete and unrestricted access to the computer/domain
Members
-------------------------------------------------------------------------------
Administrator
ACME\Domain Admins
ACME\TECHTEAM
ACME\TestUser2
The command completed successfully.