Add text or label to a connector in visio in Powershell - powershell

I am in the process of trying to create a number of Visio diagrams based on servers connected to one another by port numbers. I have been able to create the servers and the connectors, however, I am running into an issue where I am unable to label or add text to a connector between two server shapes. Here is the part of the code that was originally from the Scripting Guy column:
...
$networkinfo = Get-NetworkAdapterConfiguration -computer $computer
$Router = $NetworkStencil.Masters.Item("Router")
$shape4 = $page.Drop($Router,7.0,2.5)
$shape4.Text = "$($networkinfo.DefaultIPGateWay)"
$User = $NetworkStencil.Masters.Item("User")
$shape5 = $page.Drop($User,4.0,6.0)
$shape5.Text = "$($pcinfo.UserName)"
$etherNet = $NetworkStencil.Masters.Item("Ethernet")
$shape6 = $page.Drop($etherNet,2.2, 1.0)
$shape6.Text = "$(($networkinfo.IPAddress)[0])"
$connector = $ConnectorStencil.Masters.item("Dynamic Connector")
$shape1.AutoConnect($shape6, 0, $connector)
$shape2.AutoConnect($shape6, 0, $connector)
$shape3.AutoConnect($shape6, 0, $connector)
$shape4.AutoConnect($shape6, 0, $connector)
$shape5.AutoConnect($shape6, 0, $connector)
Can anyone help me figure out how to add text or labels to the connector between the servers?

After you do the autoconnect, try this:
$arrow=$page.Shapes('Dynamic Connector') | select-object -first 1
$arrow.NameU='Unique name for this arrow'
$arrow.Text='Label for the arrow'

Related

Converting Output to CSV and Out-Grid

I have a file as below.
I want it to convert it to CSV and want to have the out grid view of it for items Drives,Drive Type,Total Space, Current allocation and Remaining space only.
PS C:\> echo $fileSys
Storage system address: 127.0.0.1
Storage system port: 443
HTTPS connection
1: Name = Extreme Performance
Drives = 46 x 3.8T SAS Flash 4
Drive type = SAS Flash
RAID level = 5
Stripe length = 13
Total space = 149464056594432 (135.9T)
Current allocation = 108824270733312 (98.9T)
Remaining space = 40639785861120 (36.9T)
I am new to Powershell but I have tried below code for two of things but it's not even getting me desired output.
$filesys | ForEach-Object {
if ($_ -match '^.+?(?<Total space>[0-9A-F]{4}\.[0-9A-F]{4}\.[0-9A-F]{4}).+?(?<Current allocation>\d+)$') {
[PsCustomObject]#{
'Total space' = $matches['Total space']
'Current allocation' = $matches['Current allocation']
}
}
}
First and foremost, the named capture groups cannot contain spaces.
From the documentation
Named Matched Subexpressions
where name is a valid group name, and subexpression is any valid
regular expression pattern. name must not contain any punctuation
characters and cannot begin with a number.
Assuming this is a single string since your pattern attempts to grab info from multiple lines, you can forego the loop. However, even with that corrected, your pattern does not appear to match the data. It's not clear to me what you are trying to match or your desired output. Hopefully this will get you on the right track.
$filesys = #'
Storage system address: 127.0.0.1
Storage system port: 443
HTTPS connection
1: Name = Extreme Performance
Drives = 46 x 3.8T SAS Flash 4
Drive type = SAS Flash
RAID level = 5
Stripe length = 13
Total space = 149464056594432 (135.9T)
Current allocation = 108824270733312 (98.9T)
Remaining space = 40639785861120 (36.9T)
'#
if($filesys -match '(?s).+total space\s+=\s(?<totalspace>.+?)(?=\r?\n).+allocation\s+=\s(?<currentallocation>.+?)(?=\r?\n)')
{
[PsCustomObject]#{
'Total space' = $matches['totalspace']
'Current allocation' = $matches['currentallocation']
}
}
Total space Current allocation
----------- ------------------
149464056594432 (135.9T) 108824270733312 (98.9T)
Edit
If you just want the values in the parenthesis, modifying to this will achieve it.
if($filesys -match '(?s).+total space.+\((?<totalspace>.+?)(?=\)).+allocation.+\((?<currentallocation>.+?)(?=\))')
{
[PsCustomObject]#{
'Total space' = $matches['totalspace']
'Current allocation' = $matches['currentallocation']
}
}
Total space Current allocation
----------- ------------------
135.9T 36.9T
$unity=[Regex]::Matches($filesys, "\(([^)]*)\)") -replace '[(\)]','' -replace "T",""
$UnityCapacity = [pscustomobject][ordered] #{
Name = "$Display"
"Total" =$unity[0]
"Used" = $unity[1]
"Free" = $unity[2]
'Used %' = [math]::Round(($unity[1] / $unity[0])*100,2)
}``

Group team change scripts that work currently?

Any working roblox team change GUIs that you have to be in a certain group to change teams in?
Hi there, I've spent 20 minutes to code a team-changing GUI for you, follow my steps below for it to work. (This is FilteringEnabled friendly)
Step 1 Insert a LocalScript into StarterGui
Step 2 Copy the stuff from LocalScript below and paste it into your LocalScript
Step 3 Insert a Script into either Workspace or ServerScriptService (your choice)
Step 4 Copy the stuff from ServerScript below and paste it into your script
ServerScript
local teams = game:GetService("Teams")
local settings = {
["GUIHeight"] = 30, --put in a number over 20, or 100 if you want it to fill the screen
["GUIWidth"] = 40, --put in a number over 20, or 100 if you want it to fill the screen
["GUIColor"] = Color3.fromRGB(240,240,240), --color of the team changer gui
["TitleText"] = "Team Changer", --title text in the gui
["TitleFont"] = "ArialBold", --font of title
}
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.PlayerGui
local plr = game.Players.LocalPlayer
local teamGUI = Instance.new("ScreenGui",plr.PlayerGui)
local frame = Instance.new("Frame",teamGUI)
frame.AnchorPoint,frame.Size,frame.Position,frame.BackgroundColor3 = Vector2.new(0.5,0.5),UDim2.new(settings.GUIWidth/100,0,settings.GUIHeight/100,0),UDim2.new(0.5,0,0.5,0),settings.GUIColor
local title = Instance.new("TextLabel",frame)
title.Text,title.Font,title.Size,title.TextScaled,title.BackgroundTransparency = settings.TitleText,settings.TitleFont,UDim2.new(1,0,0.15,0),true,0.5
local closebutton = Instance.new("TextButton",title)
closebutton.Size,closebutton.Position,closebutton.BackgroundColor3,closebutton.Text = UDim2.new(0.1,0,1,0),UDim2.new(0.9,0,0,0),Color3.fromRGB(255,155,155),"Close"
local list = Instance.new("ScrollingFrame",frame)
list.Size,list.Position,list.BackgroundTransparency = UDim2.new(1,0,0.85,0),UDim2.new(0,0,0.15,0),1
local UILayout = Instance.new("UIListLayout",list)
local serverTeamHandler = game.ReplicatedStorage:WaitForChild("teamChanger")
local getTeams = teams:GetChildren() --this part checks if you have teams in your game (you need to have put the teams in your game already)
for i,v in pairs(getTeams) do
print("[Team " .. i .. " found]: " .. v:GetFullName())
local teamButton = Instance.new("TextButton",list)
teamButton.BackgroundColor3 = v.TeamColor.Color
teamButton.Size = UDim2.new(1,0,0,40)
teamButton.Text,teamButton.TextColor3,teamButton.TextStrokeTransparency,teamButton.TextScaled = v.Name,Color3.fromRGB(255,255,255),0.7,true
teamButton.MouseButton1Down:connect(function()
print("You changed teams. You are now in: " .. v.Name)
serverTeamHandler:InvokeServer(v)
end)
end
closebutton.MouseButton1Click:connect(function()
frame:TweenPosition(UDim2.new(0.5,0,2,0),"Out","Quad",0.5)
local returnButton = Instance.new("TextButton",teamGUI)
returnButton.Size,returnButton.Position,returnButton.Text,returnButton.TextScaled = UDim2.new(0,200,0,50),UDim2.new(0.5,-100,1,-50),"Open Team Changer",true
returnButton.MouseButton1Down:connect(function()
returnButton:Destroy()
frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Elastic",1,true)
end)
end)
LocalScript
local teamChanger = Instance.new("RemoteFunction",game.ReplicatedStorage)
teamChanger.Name = "teamChanger"
local function changeTeam(client,team)
print(client.Name .. "changed teams: now in" .. team.Name)
client.Team = team
end
teamChanger.OnServerInvoke = changeTeam
If you followed these steps correctly, you should now have a working team changing GUI in your game! It works as long as you have already inserted Teams in your game. The first few lines in the LocalScript can also be customized as well!

How do I make a working team changer GUI in roblox?

In 2018 Roblox switched coding platforms I believe, most scripts have survived, however I have failed to find a working team changer for myself this year that changes your team when clicked depending if you are in certian groups or not. My scripter says that it works in studio, but an error pops up in game that says "
TeamColor is not a valid member of PlayerGui
Stack Begin
Script 'Players.Benyal.PlayerGui.Starter GUI.TeamGui.Frame.Research and Development.LocalScript', Line 8
Stack End"
My scipter tried many different ways but it just wont work! Any seggustions?
This solution uses two scripts (one LocalScript and one Script), follow the steps below to make a team changing GUI!
local teams = game:GetService("Teams")
local settings = {
["GUIHeight"] = 30, --put in a number over 20, or 100 if you want it to fill the screen
["GUIWidth"] = 40, --put in a number over 20, or 100 if you want it to fill the screen
["GUIColor"] = Color3.fromRGB(240,240,240), --color of the team changer gui
["TitleText"] = "Team Changer", --title text in the gui
["TitleFont"] = "ArialBold", --font of title
}
repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.PlayerGui
local plr = game.Players.LocalPlayer
local teamGUI = Instance.new("ScreenGui",plr.PlayerGui)
local frame = Instance.new("Frame",teamGUI)
frame.AnchorPoint,frame.Size,frame.Position,frame.BackgroundColor3 = Vector2.new(0.5,0.5),UDim2.new(settings.GUIWidth/100,0,settings.GUIHeight/100,0),UDim2.new(0.5,0,0.5,0),settings.GUIColor
local title = Instance.new("TextLabel",frame)
title.Text,title.Font,title.Size,title.TextScaled,title.BackgroundTransparency = settings.TitleText,settings.TitleFont,UDim2.new(1,0,0.15,0),true,0.5
local closebutton = Instance.new("TextButton",title)
closebutton.Size,closebutton.Position,closebutton.BackgroundColor3,closebutton.Text = UDim2.new(0.1,0,1,0),UDim2.new(0.9,0,0,0),Color3.fromRGB(255,155,155),"Close"
local list = Instance.new("ScrollingFrame",frame)
list.Size,list.Position,list.BackgroundTransparency = UDim2.new(1,0,0.85,0),UDim2.new(0,0,0.15,0),1
local UILayout = Instance.new("UIListLayout",list)
local serverTeamHandler = game.ReplicatedStorage:WaitForChild("teamChanger")
local getTeams = teams:GetChildren() --this part checks if you have teams in your game (you need to have put the teams in your game already)
for i,v in pairs(getTeams) do
print("[Team " .. i .. " found]: " .. v:GetFullName())
local teamButton = Instance.new("TextButton",list)
teamButton.BackgroundColor3 = v.TeamColor.Color
teamButton.Size = UDim2.new(1,0,0,40)
teamButton.Text,teamButton.TextColor3,teamButton.TextStrokeTransparency,teamButton.TextScaled = v.Name,Color3.fromRGB(255,255,255),0.7,true
teamButton.MouseButton1Down:connect(function()
print("You changed teams. You are now in: " .. v.Name)
serverTeamHandler:InvokeServer(v)
end)
end
closebutton.MouseButton1Click:connect(function()
frame:TweenPosition(UDim2.new(0.5,0,2,0),"Out","Quad",0.5)
local returnButton = Instance.new("TextButton",teamGUI)
returnButton.Size,returnButton.Position,returnButton.Text,returnButton.TextScaled = UDim2.new(0,200,0,50),UDim2.new(0.5,-100,1,-50),"Open Team Changer",true
returnButton.MouseButton1Down:connect(function()
returnButton:Destroy()
frame:TweenPosition(UDim2.new(0.5,0,0.5,0),"Out","Elastic",1,true)
end)
end)
Step 1 Insert a LocalScript into StarterGui
Step 2 Copy the stuff above and paste it into this LocalScript
Step 3 Insert a Script into either Workspace or ServerScriptService (your choice)
Step 4 Copy the stuff below and paste it into the Script
local teamChanger = Instance.new("RemoteFunction",game.ReplicatedStorage)
teamChanger.Name = "teamChanger"
local function changeTeam(client,team)
print(client.Name .. "changed teams: now in" .. team.Name)
client.Team = team
end
teamChanger.OnServerInvoke = changeTeam
If you followed these steps correctly, you should now have a working team changing GUI in your game! It works as long as you have already inserted Teams in your game. The first few lines in the LocalScript can also be customized as well!

Matching 'Network Location' icons

I am using the following code to create a Network Location, but the result is not exactly the same as when doing it manually. The icon from shell32.dll is smaller, lower res and has a frame, as seen here on the left. Is there any way to match the "native" look with PowerShell?
$linkFolder = New-Item -name:$location.name -path:"$nethoodPath\$($location.name)" -type:Directory -errorAction:stop
# Create the ini file
$desktopIniContent = (
'[.ShellClassInfo]',
'CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}',
'Flags=2',
'ConfirmFileOp=1'
) -join "`r`n"
$desktopIniContent | Out-File -filePath:"$nethoodPath\$($location.name)\Desktop.ini"
# Create the shortcut file
$link = $shell.Createshortcut("$nethoodPath\$($location.name)\target.lnk")
$link.TargetPath = $location.value
$link.IconLocation = "%SystemRoot%\system32\SHELL32.DLL, 275"
$link.Description = $location.value
$link.WorkingDirectory = $location.value
$link.Save()
# Set attributes on the files & folders
Set-ItemProperty "$nethoodPath\$($location.name)\Desktop.ini" -name:Attributes -value:([IO.FileAttributes]::System -bxor [IO.FileAttributes]::Hidden) -errorAction:stop
Set-ItemProperty "$nethoodPath\$($location.name)" -name:Attributes -value:([IO.FileAttributes]::ReadOnly) -errorAction:stop
The icon on the right hand side can be found in imageres.dll (the Windows image resource library), icon 138 (index 137):
$link.IconLocation = "%SystemRoot%\system32\imageres,137"
It would seem that the horrible resolution of the shell32.dll,275 version is a bug/blunder that has been fixed by Microsoft subsequently:
Windows 7:
The shell32.dll version scales horribly
Windows 10:
On Windows 10, shell32.dll,275 scales to "Extra Large Icons"-size perfectly fine

Convert powershell cmdlet to C#

How could I convert the follow powershell command to C# code, especially parameters for -index.
Get-Mailbox | select-object -index 0, 1, 2, 3, 4, 5
I just want to retrieve the mail box many times to avoid extremely big memory usage.
How to set 0, 1, 2, 3, 4, 5 to CommandParameters?
I'm not a programmer but this is should get you closer:
Command cmdMailbox = new Command("Get-Mailbox");
cmdMailbox.Parameters.Add("Identity", 'someone');
Command cmdSelect = new Command("Select-Object");
int[] indexes = new int[] {0,1,2,3,4,5};
cmdSelect.Parameters.Add("Index",indexes );