blister911
MIS
Hello,
I've gotten to the point where I could use some help.
I've written a script to remove profiles from our Citrix servers. (Our User Profile Management is suppose to remove the profiles when the users log out, but that doesn't always happen.)
I'm pretty sure the script is working because it did remove a couple of users. However, for the majority I'm getting an exception error. See below where it removed the "Builder" profile, but failed on paige. The users are not logged in. At the time this script was run, there were NO users logged into the server, remotely.
Here is my script in case it helps. It's a bit messy, because I've been doing a lot of troubleshooting.
I've checked about all I can think of to check. Any assistance is appreciated.
Thanks.
Light travels faster than sound. That's why some people appear bright until you hear them speak.
I've gotten to the point where I could use some help.
I've written a script to remove profiles from our Citrix servers. (Our User Profile Management is suppose to remove the profiles when the users log out, but that doesn't always happen.)
I'm pretty sure the script is working because it did remove a couple of users. However, for the majority I'm getting an exception error. See below where it removed the "Builder" profile, but failed on paige. The users are not logged in. At the time this script was run, there were NO users logged into the server, remotely.
Code:
Checking APP-SP-5. Please wait...
C:\Users\Builder.IQTEST-SP-53
C:\Users\paige14064
Exception calling "Delete" with "0" argument(s): ""
At U:\Exchange_Scripts\Remove_BackupTemp_Citrix_Profiles.ps1:71 char:17
+ $user.delete <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Here is my script in case it helps. It's a bit messy, because I've been doing a lot of troubleshooting.
Code:
##-----------------------------------------------------------------------------------------------------##
## MAIN SCRIPT
##-----------------------------------------------------------------------------------------------------##
## Include function library
. .\PPC_Function_Library.ps1
PPC-Add-Snapins
#Import-Module PSTerminalServices
## User search prompt variables
$All = new-object System.Management.Automation.Host.ChoiceDescription "&All"
$User = new-object System.Management.Automation.Host.ChoiceDescription "&Single User"
$search_choices = [System.Management.Automation.Host.ChoiceDescription[]] ($All, $User)
$search_title = ""
## set variable to check all servers
$list = 2
## Array of servers
#$serverlist = PPC-Get-Citrix-Servers $list
$serverlist = @("APP-SP-5")
$exclude_list = @("*Administrator*","*classic*","*svcpvs*")
$script_message = "Do you want the script to remove all temporary and backup profiles or just those for a specific user?"
$script_answer = $host.ui.PromptForChoice($search_title,$script_message,$search_choices,1)
if ($script_answer)
{
[string]$solo_user = PPC-Get-User
$solo_user = $solo_user.trim()
$username = "*"+$solo_user+"*"
}
foreach ($server in $serverlist)
{
write-host "Checking $server. Please wait..." -foregroundcolor "darkcyan"
$users = Get-WmiObject Win32_UserProfile -ComputerName $server -Filter "Loaded='FALSE' And Special='FALSE' AND LocalPath != NULL"
if ($script_answer)
{
$temp = @()
$temp = $users
$users = @()
foreach ($t in $temp)
{
if ($t.localpath -like $username)
{$users += $t}
}
}
foreach ($user in $users)
{
$skip = $FALSE
foreach ($exclude in $exclude_list)
{
if ($user.localpath -like $exclude)
{
$skip = $TRUE
break
}
}
if (!$skip)
{
$path = $user.localpath
write-host $path -foregroundcolor "DarkYellow"
$user.delete()
}
}
}
write-host "";""
write-host "End of Script"
write-host "";""
I've checked about all I can think of to check. Any assistance is appreciated.
Thanks.
Light travels faster than sound. That's why some people appear bright until you hear them speak.