Hi all,
Firstly, what a great resource. Thanks to everyone who dedicates their time to helping the powershell community. I am new to powershell and only which that I got on the powershell train 5 years ago when I entered IT.
I am wondering if someone can assist and explain how to use a variable when using invoke-command. Here is a part of a script I am working on:
$data = Import-Csv C:\Scripts\ExchangeServerData.csv
foreach($d in $data){
Invoke-Command -ComputerName $d.MailboxServer -ScriptBlock {
Get-Disk | Where-Object {$_.PartitionStyle -eq "Raw"} | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "$($d.ActiveDatabase)-Active" -Confirm:$false
}
}
The issue I am having is towards the end of that main ‘one-liner’, where I have tried to use -NewFileSystemLabel “$($d.ActiveDatabase)-Active”. The value from my CSV file under ‘ActiveDatabase’ did not get passed through and instead I ended up with a volume that has a label of ‘-Active’.
Can someone shed some light on how to make this work and more importantly (for me), take a few mins to explain it as well. I understand that the variable does not work, because the remote machine does not know about the local variable.
Also, is there a way to use powershell to assign this newly created volume a mount point instead of a drive letter?
Cheers!