tri_94 Posted March 24, 2020 Posted March 24, 2020 Hi there I'm creating a tool to change quotas via powershell however we many servers. I would like to be able to type username and it automatically set the server to connect to inorder to change the quota. i was planning to use this line, is there a better way or is it possible to split the full path and return just the servername? Get-AdUser -filter {SamAccountName -eq $Input} -properties * | Select-Object -ExpandProperty HomeDirectory Thanks
tri_94 Posted March 24, 2020 Author Posted March 24, 2020 Paths are as follows. So would like it to split path up to \ after server name if that makes sense. \\Server-01\Documents\User\Documents \\ServerB-01\Documents\User\Documents
HPlum78 Posted March 24, 2020 Posted March 24, 2020 So this will get you the server name:- $str = '\\Server-01\Documents\User\Documents' $StrServer = $Str.TrimStart('\\').Split('\') $StrServer[0] H.
tri_94 Posted March 24, 2020 Author Posted March 24, 2020 Now struggling with the next part I'm using Invoke-Command -ComputerName $StrServer[0] -ScriptBlock{ which works perfectly but my script is now passing the username. I've tried setting this at the beginning of the script like this $global:input = Read-Host "Enter Username" but after Invoke-Command -ComputerName $StrServer[0] -ScriptBlock{ but when i use $input its empty Am i doing something wrong? Thanks
tri_94 Posted March 24, 2020 Author Posted March 24, 2020 Think i've got it working using $local = $input Invoke-Command -ComputerName $StrServer[0] -ArgumentList $local -ScriptBlock{ param($local)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now