|
Replies:
4
-
Pages:
1
-
Last Post:
Apr 18, 2012 1:02 AM
by: Hans Wurst
|
|
|
Posts:
2
Registered:
4/16/12
|
|
|
|
Script to disable 'annon*' local users on multiple servers (Citrix Servers)
Posted:
Apr 16, 2012 11:45 AM
|
|
|
I'm looking for some PS script help because, well, I'm just learning and not very good yet. I would like to use a PS script that calls a csv file containing server names and then disables specific local users on each server. These local users are installed during Citrix XenApp role install to provide support for optional anonymous users. The local anonymous accounts created on each server follow the name convention of 'anon001', 'anon002', etc... up through 'anon014'. We currently have a significant # of servers and this wasn't done prior to creating our image in VMware so I need to go back and disable all of them on existing servers.
Thanks!
|
|
|
Posts:
134
Registered:
2/9/12
|
|
|
|
Re: Script to disable 'annon*' local users on multiple servers (Citrix Servers)
Posted:
Apr 16, 2012 1:25 PM
in response to: dorz3l
|
|
|
Hello, try this:
From here "http://gallery.technet.microsoft.com/scriptcenter/f75801e7-169a-4737-952c-1341abea5823" I got this function:
<pre class="powershell">Function Remove-LocalUser { [CmdletBinding()] Param( [Parameter(Position=0, Mandatory=$True, ValueFromPipeline=$True)] [string]$userName, [string]$computerName = $env:ComputerName ) $User = [ADSI]"WinNT://$computerName" $user.Delete("User",$userName) } </pre>$names = "anon001", "anon002", "anon003", "anon004", "anon005", "anon006", "anon007", "anon008", "anon009", "anon010", "anon011", "anon012", "anon013", "anon014"
import-csv "path_to_csvfile" | foreach-object { $_=$pc; $names | foreach-object { <pre class="powershell">Remove-LocalUser -username $_ -computername $pc</pre>}}
Tell me if it worked.
|
|
|
Posts:
134
Registered:
2/9/12
|
|
|
|
Re: Script to disable 'annon*' local users on multiple servers (Citrix Servers)
Posted:
Apr 16, 2012 1:31 PM
in response to: dorz3l
|
|
|
Sorry I dont know what happened. Here it is once again:
Function Remove-LocalUser { [CmdletBinding()] Param( [Parameter(Position=0, Mandatory=$True, ValueFromPipeline=$True)] [string]$userName, [string]$computerName = $env:ComputerName ) $User = [ADSI]"WinNT://$computerName" $user.Delete("User",$userName) }
$names = "anon001", "anon002", "anon003", "anon004", "anon005", "anon006", "anon007", "anon008", "anon009", "anon010", "anon011", "anon012", "anon013", "anon014"
import-csv "path_to_csvfile" | foreach-object { $_=$pc; $names | foreach-object {
Remove-LocalUser -username $_ -computername $pc
}}
|
|
|
Posts:
2
Registered:
4/16/12
|
|
|
|
Re: Script to disable 'annon*' local users on multiple servers (Citrix Servers)
Posted:
Apr 17, 2012 5:58 AM
in response to: Hans Wurst
|
|
|
forgive my ignornace on this but the function looks like it's performing a delete as opposed to simply disabling the account. is that correct or am I misunderstanding?
thanks!
|
|
|
Posts:
134
Registered:
2/9/12
|
|
|
|
Re: Script to disable 'annon*' local users on multiple servers (Citrix Servers)
Posted:
Apr 18, 2012 1:02 AM
in response to: dorz3l
|
|
|
Hello dorz3l, your absolutely right! Please excuse my improper reading....
so try this one:
function Set-LocalUser { [CmdletBinding()] Param( [Parameter(Position=0, Mandatory=$True, ValueFromPipeline=$True)] [string]$userName, [Parameter(Position=1, Mandatory=$True, ValueFromPipeline=$True, ParameterSetName='EnableUser')] [string]$password, [Parameter(ParameterSetName='EnableUser')] [switch]$enable, [Parameter(ParameterSetName='DisableUser')] [switch]$disable, [string]$computerName = $env:ComputerName, [string]$description = "modified via powershell" ) $EnableUser = 512 # ADS_USER_FLAG_ENUM enumeration value from SDK $DisableUser = 2 # ADS_USER_FLAG_ENUM enumeration value from SDK $User = [ADSI]"WinNT://$computerName/$userName,User" if($enable) { $User.setpassword($password) $User.description = $description $User.userflags = $EnableUser $User.setinfo() } #end if enable if($disable) { $User.description = $description $User.userflags = $DisableUser $User.setinfo() } #end if disable } #end function Set-LocalUser
$names = "anon001", "anon002", "anon003", "anon004", "anon005", "anon006", "anon007", "anon008", "anon009", "anon010", "anon011", "anon012", "anon013", "anon014"
import-csv "path_to_csvfile" | foreach-object { $_=$pc; $names | foreach-object {
Set-LocalUser -username $_ -disable -computername $pc
}}
|
|
|
|
Legend
|
|
MVP: 2501
+
pts
|
|
Guru: 2001
- 2500
pts
|
|
Expert: 751
- 2000
pts
|
|
Enthusiast: 31
- 750
pts
|
|
Novice: 0
- 30
pts
|
|
Moderators
|
|
Helpful answer
(5 pts)
|
|
Answered
(10 pts)
|
|